Skip to content

Commit

Permalink
fix tests[7]
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Aug 15, 2024
1 parent 3ed78e4 commit d48659d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 5 additions & 7 deletions include/swoole_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,11 @@ struct Socket {
return ::read(fd, __buf, __len);
}

ssize_t read_sync(void *__buf, size_t __len, int timeout_ms = -1) {
if (wait_event(timeout_ms, SW_EVENT_READ) == SW_OK) {
return read(__buf, __len);
} else {
return -1;
}
}
/**
* Read data from the socket synchronously without setting non-blocking or blocking IO,
* and allow interruptions by signals.
*/
ssize_t read_sync(void *__buf, size_t __len, int timeout_ms = -1);

int shutdown(int __how) {
return ::shutdown(fd, __how);
Expand Down
11 changes: 11 additions & 0 deletions src/network/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,17 @@ ssize_t Socket::send_async(const void *__buf, size_t __n) {
}
}

ssize_t Socket::read_sync(void *__buf, size_t __len, int timeout_ms) {
struct pollfd event;
event.fd = fd;
event.events = POLLIN;
if (poll(&event, 1, timeout_ms) == 1) {
return read(__buf, __len);
} else {
return -1;
}
}

ssize_t Socket::readv(IOVector *io_vector) {
ssize_t retval;

Expand Down
2 changes: 1 addition & 1 deletion src/server/master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ ListenPort *Server::add_port(SocketType type, const char *host, int port) {
}

void Server::master_signal_handler(int signo) {
swoole_trace_log(SW_TRACE_SERVER, "signal[%d] %s triggered in %d", sig, swoole_signal_to_str(sig), getpid());
swoole_trace_log(SW_TRACE_SERVER, "signal[%d] %s triggered in %d", signo, swoole_signal_to_str(signo), getpid());

Server *serv = sw_server();
if (!SwooleG.running || !serv || !serv->is_running()) {
Expand Down

0 comments on commit d48659d

Please sign in to comment.