mirror of
https://github.com/lxsang/antd-tunnel-plugin
synced 2024-12-27 02:18:20 +01:00
use poll instead of select on client sockets whose fid may be greater than 1024
This commit is contained in:
parent
4f8f020cd8
commit
1cb8bfa32b
20
tunnel.c
20
tunnel.c
@ -19,6 +19,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
#define MAX_CHANNEL_NAME 64
|
#define MAX_CHANNEL_NAME 64
|
||||||
#define HOT_LINE_SOCKET "antd_hotline.sock"
|
#define HOT_LINE_SOCKET "antd_hotline.sock"
|
||||||
@ -1037,7 +1038,7 @@ void *handle(void *rq_data)
|
|||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
int status;
|
int status;
|
||||||
fd_set fd_in;
|
struct pollfd pfd;
|
||||||
int offset;
|
int offset;
|
||||||
bst_node_t *node = NULL;
|
bst_node_t *node = NULL;
|
||||||
antd_tunnel_key_t *key_p = NULL;
|
antd_tunnel_key_t *key_p = NULL;
|
||||||
@ -1099,13 +1100,13 @@ void *handle(void *rq_data)
|
|||||||
// session is valid, continue
|
// session is valid, continue
|
||||||
timeout.tv_sec = 0;
|
timeout.tv_sec = 0;
|
||||||
timeout.tv_usec = PROCESS_TIMEOUT;
|
timeout.tv_usec = PROCESS_TIMEOUT;
|
||||||
FD_ZERO(&fd_in);
|
pfd.fd = client->sock;
|
||||||
FD_SET(client->sock, &fd_in);
|
pfd.events = POLLIN;
|
||||||
status = select(client->sock + 1, &fd_in, NULL, NULL, &timeout);
|
status = poll(&pfd, 1, PROCESS_TIMEOUT);
|
||||||
switch (status)
|
switch (status)
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
LOG("Error %d on select()\n", errno);
|
ERROR("Error on poll(): %s", strerror(errno));
|
||||||
pthread_mutex_lock(&g_tunnel.lock);
|
pthread_mutex_lock(&g_tunnel.lock);
|
||||||
bst_for_each(g_tunnel.channels, unsubscribe_notify, argv, 1);
|
bst_for_each(g_tunnel.channels, unsubscribe_notify, argv, 1);
|
||||||
pthread_mutex_unlock(&g_tunnel.lock);
|
pthread_mutex_unlock(&g_tunnel.lock);
|
||||||
@ -1117,6 +1118,15 @@ void *handle(void *rq_data)
|
|||||||
select(0, NULL, NULL, NULL, &timeout);
|
select(0, NULL, NULL, NULL, &timeout);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if(pfd.revents & (POLLERR | POLLHUP))
|
||||||
|
{
|
||||||
|
ERROR("POLLHUP or POLLERR found");
|
||||||
|
pthread_mutex_lock(&g_tunnel.lock);
|
||||||
|
bst_for_each(g_tunnel.channels, unsubscribe_notify, argv, 1);
|
||||||
|
pthread_mutex_unlock(&g_tunnel.lock);
|
||||||
|
return task;
|
||||||
|
break;
|
||||||
|
}
|
||||||
pthread_mutex_lock(&g_tunnel.lock);
|
pthread_mutex_lock(&g_tunnel.lock);
|
||||||
h = ws_read_header(rq->client);
|
h = ws_read_header(rq->client);
|
||||||
pthread_mutex_unlock(&g_tunnel.lock);
|
pthread_mutex_unlock(&g_tunnel.lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user