mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
Introduce LWS_POLLIN, LWS_POLLOUT and LWS_POLLHUP
This commit is contained in:
parent
e85ddb4822
commit
b47f87b04b
5 changed files with 37 additions and 40 deletions
|
@ -186,7 +186,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
|
|||
* must do specifically a POLLOUT poll to hear
|
||||
* about the connect completion
|
||||
*/
|
||||
lws_change_pollfd(wsi, 0, POLLOUT);
|
||||
lws_change_pollfd(wsi, 0, LWS_POLLOUT);
|
||||
|
||||
return wsi;
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
|
|||
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
|
||||
pfd.fd = wsi->sock;
|
||||
pfd.revents = POLLIN;
|
||||
pfd.revents = LWS_POLLIN;
|
||||
|
||||
n = libwebsocket_service_fd(context, &pfd);
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
|
||||
/* handle proxy hung up on us */
|
||||
|
||||
if (pollfd->revents & (POLLERR | POLLHUP)) {
|
||||
if (pollfd->revents & LWS_POLLHUP) {
|
||||
|
||||
lwsl_warn("Proxy connection %p (fd=%d) dead\n",
|
||||
(void *)wsi, pollfd->fd);
|
||||
|
@ -118,7 +118,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
* happening at a time when there's no real connection yet
|
||||
*/
|
||||
|
||||
lws_change_pollfd(wsi, POLLOUT, 0);
|
||||
lws_change_pollfd(wsi, LWS_POLLOUT, 0);
|
||||
|
||||
/* we can retry this... just cook the SSL BIO the first time */
|
||||
|
||||
|
@ -356,7 +356,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
|
||||
/* handle server hung up on us */
|
||||
|
||||
if (pollfd->revents & (POLLERR | POLLHUP)) {
|
||||
if (pollfd->revents & LWS_POLLHUP) {
|
||||
|
||||
lwsl_debug("Server connection %p (fd=%d) dead\n",
|
||||
(void *)wsi, pollfd->fd);
|
||||
|
@ -364,7 +364,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
|
|||
goto bail3;
|
||||
}
|
||||
|
||||
if (!(pollfd->revents & POLLIN))
|
||||
if (!(pollfd->revents & LWS_POLLIN))
|
||||
break;
|
||||
|
||||
/* interpret the server response */
|
||||
|
|
|
@ -144,7 +144,7 @@ int
|
|||
insert_wsi_socket_into_fds(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi)
|
||||
{
|
||||
struct libwebsocket_pollargs pa = { wsi->sock, POLLIN, 0 };
|
||||
struct libwebsocket_pollargs pa = { wsi->sock, LWS_POLLIN, 0 };
|
||||
|
||||
if (context->fds_count >= context->max_fds) {
|
||||
lwsl_err("Too many fds (%d)\n", context->max_fds);
|
||||
|
@ -170,7 +170,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context,
|
|||
context->lws_lookup[wsi->sock] = wsi;
|
||||
wsi->position_in_fds_table = context->fds_count;
|
||||
context->fds[context->fds_count].fd = wsi->sock;
|
||||
context->fds[context->fds_count].events = POLLIN;
|
||||
context->fds[context->fds_count].events = LWS_POLLIN;
|
||||
#ifdef LWS_USE_LIBEV
|
||||
if (context && context->io_loop && LWS_LIBEV_ENABLED(context))
|
||||
ev_io_start(context->io_loop, (struct ev_io *)&wsi->w_read);
|
||||
|
@ -918,7 +918,7 @@ user_service:
|
|||
/* one shot */
|
||||
|
||||
if (pollfd) {
|
||||
lws_change_pollfd(wsi, POLLOUT, 0);
|
||||
lws_change_pollfd(wsi, LWS_POLLOUT, 0);
|
||||
#ifdef LWS_USE_LIBEV
|
||||
if (LWS_LIBEV_ENABLED(context))
|
||||
ev_io_stop(context->io_loop,
|
||||
|
@ -984,7 +984,7 @@ static int lws_poll_listen_fd(struct libwebsocket_pollfd* fd)
|
|||
fd_set readfds;
|
||||
struct timeval tv = { 0, 0 };
|
||||
|
||||
assert(fd->events == POLLIN);
|
||||
assert(fd->events == LWS_POLLIN);
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(fd->fd, &readfds);
|
||||
|
@ -1143,8 +1143,8 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
|
||||
/* handle session socket closed */
|
||||
|
||||
if ((!(pollfd->revents & POLLIN)) &&
|
||||
(pollfd->revents & (POLLERR | POLLHUP))) {
|
||||
if ((!(pollfd->revents & LWS_POLLIN)) &&
|
||||
(pollfd->revents & LWS_POLLHUP)) {
|
||||
|
||||
lwsl_debug("Session Socket %p (fd=%d) dead\n",
|
||||
(void *)wsi, pollfd->fd);
|
||||
|
@ -1170,7 +1170,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
|
||||
/* the guy requested a callback when it was OK to write */
|
||||
|
||||
if ((pollfd->revents & POLLOUT) &&
|
||||
if ((pollfd->revents & LWS_POLLOUT) &&
|
||||
wsi->state == WSI_STATE_ESTABLISHED &&
|
||||
lws_handle_POLLOUT_event(context, wsi, pollfd) < 0) {
|
||||
lwsl_info("libwebsocket_service_fd: closing\n");
|
||||
|
@ -1191,7 +1191,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
|
|||
|
||||
/* any incoming data ready? */
|
||||
|
||||
if (!(pollfd->revents & POLLIN))
|
||||
if (!(pollfd->revents & LWS_POLLIN))
|
||||
break;
|
||||
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
|
@ -1328,10 +1328,10 @@ libwebsocket_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
|
|||
eventfd.fd = watcher->fd;
|
||||
eventfd.revents = EV_NONE;
|
||||
if (revents & EV_READ)
|
||||
eventfd.revents |= POLLIN;
|
||||
eventfd.revents |= LWS_POLLIN;
|
||||
|
||||
if (revents & EV_WRITE)
|
||||
eventfd.revents |= POLLOUT;
|
||||
eventfd.revents |= LWS_POLLOUT;
|
||||
|
||||
libwebsocket_service_fd(context,&eventfd);
|
||||
}
|
||||
|
@ -1521,10 +1521,10 @@ libwebsocket_service(struct libwebsocket_context *context, int timeout_ms)
|
|||
pfd = &context->fds[i];
|
||||
if (pfd->fd == context->listen_service_fd)
|
||||
continue;
|
||||
if (pfd->events & POLLOUT) {
|
||||
if (pfd->events & LWS_POLLOUT) {
|
||||
if (context->lws_lookup[pfd->fd]->sock_send_blocking)
|
||||
continue;
|
||||
pfd->revents = POLLOUT;
|
||||
pfd->revents = LWS_POLLOUT;
|
||||
n = libwebsocket_service_fd(context, pfd);
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
@ -1555,11 +1555,11 @@ libwebsocket_service(struct libwebsocket_context *context, int timeout_ms)
|
|||
return -1;
|
||||
}
|
||||
|
||||
pfd->revents = (networkevents.lNetworkEvents & LWS_POLLIN) ? POLLIN : 0;
|
||||
pfd->revents = (networkevents.lNetworkEvents & LWS_POLLIN) ? LWS_POLLIN : 0;
|
||||
|
||||
if (networkevents.lNetworkEvents & LWS_POLLOUT) {
|
||||
context->lws_lookup[pfd->fd]->sock_send_blocking = FALSE;
|
||||
pfd->revents |= POLLOUT;
|
||||
pfd->revents |= LWS_POLLOUT;
|
||||
}
|
||||
|
||||
return libwebsocket_service_fd(context, pfd);
|
||||
|
@ -1762,7 +1762,7 @@ lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or)
|
|||
*/
|
||||
if (pa.prev_events != pa.events) {
|
||||
#ifdef _WIN32
|
||||
if ((pfd->events & POLLIN))
|
||||
if ((pfd->events & LWS_POLLIN))
|
||||
networkevents |= LWS_POLLIN;
|
||||
|
||||
if (WSAEventSelect(wsi->sock,
|
||||
|
@ -1825,7 +1825,7 @@ libwebsocket_callback_on_writable(struct libwebsocket_context *context,
|
|||
return -1;
|
||||
}
|
||||
|
||||
lws_change_pollfd(wsi, 0, POLLOUT);
|
||||
lws_change_pollfd(wsi, 0, LWS_POLLOUT);
|
||||
#ifdef LWS_USE_LIBEV
|
||||
if (LWS_LIBEV_ENABLED(context))
|
||||
ev_io_start(context->io_loop, (struct ev_io *)&wsi->w_write);
|
||||
|
@ -2001,9 +2001,9 @@ _libwebsocket_rx_flow_control(struct libwebsocket *wsi)
|
|||
/* adjust the pollfd for this wsi */
|
||||
|
||||
if (wsi->u.ws.rxflow_change_to & LWS_RXFLOW_ALLOW)
|
||||
lws_change_pollfd(wsi, 0, POLLIN);
|
||||
lws_change_pollfd(wsi, 0, LWS_POLLIN);
|
||||
else
|
||||
lws_change_pollfd(wsi, POLLIN, 0);
|
||||
lws_change_pollfd(wsi, LWS_POLLIN, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -2328,7 +2328,7 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
|||
|
||||
/* use the read end of pipe as first item */
|
||||
context->fds[0].fd = context->dummy_pipe_fds[0];
|
||||
context->fds[0].events = POLLIN;
|
||||
context->fds[0].events = LWS_POLLIN;
|
||||
context->fds[0].revents = 0;
|
||||
context->fds_count = 1;
|
||||
#endif
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#define LWS_EINTR WSAEINTR
|
||||
#define LWS_EISCONN WSAEISCONN
|
||||
#define LWS_EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define LWS_POLLHUP (FD_CLOSE)
|
||||
#define LWS_POLLIN (FD_READ | FD_ACCEPT)
|
||||
#define LWS_POLLOUT (FD_WRITE)
|
||||
#define MSG_NOSIGNAL 0
|
||||
|
@ -85,13 +86,6 @@
|
|||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#define LWS_INVALID_FILE INVALID_HANDLE_VALUE
|
||||
|
||||
#if defined(__MINGW32__) || defined(__MINGW64__) || _WIN32_WINNT < 0x0600
|
||||
#define POLLIN 0x01
|
||||
#define POLLOUT 0x04
|
||||
#define POLLERR 0x08
|
||||
#define POLLHUP 0x10
|
||||
#endif
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -119,6 +113,9 @@
|
|||
#define LWS_EISCONN EISCONN
|
||||
#define LWS_EWOULDBLOCK EWOULDBLOCK
|
||||
#define LWS_INVALID_FILE -1
|
||||
#define LWS_POLLHUP (POLLHUP|POLLERR)
|
||||
#define LWS_POLLIN (POLLIN)
|
||||
#define LWS_POLLOUT (POLLOUT)
|
||||
#define compatible_close(fd) close(fd);
|
||||
#endif
|
||||
|
||||
|
|
16
lib/server.c
16
lib/server.c
|
@ -124,7 +124,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
/* pending truncated sends have uber priority */
|
||||
|
||||
if (wsi->truncated_send_malloc) {
|
||||
if (pollfd->revents & POLLOUT)
|
||||
if (pollfd->revents & LWS_POLLOUT)
|
||||
lws_issue_raw(wsi, wsi->truncated_send_malloc +
|
||||
wsi->truncated_send_offset,
|
||||
wsi->truncated_send_len);
|
||||
|
@ -138,7 +138,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
|
||||
/* any incoming data ready? */
|
||||
|
||||
if (pollfd->revents & POLLIN) {
|
||||
if (pollfd->revents & LWS_POLLIN) {
|
||||
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
if (wsi->ssl)
|
||||
|
@ -183,11 +183,11 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
|
||||
/* this handles POLLOUT for http serving fragments */
|
||||
|
||||
if (!(pollfd->revents & POLLOUT))
|
||||
if (!(pollfd->revents & LWS_POLLOUT))
|
||||
break;
|
||||
|
||||
/* one shot */
|
||||
lws_change_pollfd(wsi, POLLOUT, 0);
|
||||
lws_change_pollfd(wsi, LWS_POLLOUT, 0);
|
||||
#ifdef LWS_USE_LIBEV
|
||||
ev_io_stop(context->io_loop,(struct ev_io*)&(wsi->w_write));
|
||||
#endif /* LWS_USE_LIBEV */
|
||||
|
@ -216,7 +216,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
|
||||
/* pollin means a client has connected to us then */
|
||||
|
||||
if (!(pollfd->revents & POLLIN))
|
||||
if (!(pollfd->revents & LWS_POLLIN))
|
||||
break;
|
||||
|
||||
/* listen socket got an unencrypted connection... */
|
||||
|
@ -353,7 +353,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
|
||||
case LWS_CONNMODE_SSL_ACK_PENDING:
|
||||
|
||||
lws_change_pollfd(wsi, POLLOUT, 0);
|
||||
lws_change_pollfd(wsi, LWS_POLLOUT, 0);
|
||||
#ifdef LWS_USE_LIBEV
|
||||
ev_io_stop(context->io_loop,(struct ev_io*)&(wsi->w_write));
|
||||
#endif /* LWS_USE_LIBEV */
|
||||
|
@ -400,7 +400,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
m, ERR_error_string(m, NULL));
|
||||
|
||||
if (m == SSL_ERROR_WANT_READ) {
|
||||
lws_change_pollfd(wsi, 0, POLLIN);
|
||||
lws_change_pollfd(wsi, 0, LWS_POLLIN);
|
||||
#ifdef LWS_USE_LIBEV
|
||||
ev_io_start(context->io_loop,(struct ev_io*)&(wsi->w_read));
|
||||
#endif /* LWS_USE_LIBEV */
|
||||
|
@ -408,7 +408,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
|
|||
break;
|
||||
}
|
||||
if (m == SSL_ERROR_WANT_WRITE) {
|
||||
lws_change_pollfd(wsi, 0, POLLOUT);
|
||||
lws_change_pollfd(wsi, 0, LWS_POLLOUT);
|
||||
#ifdef LWS_USE_LIBEV
|
||||
ev_io_start(context->io_loop,(struct ev_io*)&(wsi->w_write));
|
||||
#endif /* LWS_USE_LIBEV */
|
||||
|
|
Loading…
Add table
Reference in a new issue