Fix protocol probe. Will detect ADC and TLS handshake - any other request
will simply cause the hub to close the connection. Fix problems with write events not being processed due to a read event taking presendence. Fix bug #86: Windows does not have "getrlimit()".
This commit is contained in:
@@ -180,7 +180,13 @@ void net_con_initialize(struct net_connection* con, int sd, net_connection_cb ca
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void net_con_reinitialize(struct net_connection* con, net_connection_cb callback, const void* ptr, int events)
|
||||
{
|
||||
uhub_assert(con);
|
||||
con->callback = callback;
|
||||
con->ptr = (void*) ptr;
|
||||
net_con_update(con, events);
|
||||
}
|
||||
|
||||
void net_con_update(struct net_connection* con, int ev)
|
||||
{
|
||||
@@ -393,6 +399,41 @@ ssize_t net_con_recv(struct net_connection* con, void* buf, size_t len)
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t net_con_peek(struct net_connection* con, void* buf, size_t len)
|
||||
{
|
||||
uhub_assert(con);
|
||||
|
||||
#ifdef SSL_SUPPORT
|
||||
if (!con->ssl)
|
||||
{
|
||||
#endif
|
||||
int ret = net_recv(con->sd, buf, len, MSG_PEEK);
|
||||
#ifdef NETWORK_DUMP_DEBUG
|
||||
LOG_PROTO("net_recv: ret=%d (MSG_PEEK)", ret);
|
||||
#endif
|
||||
if (ret > 0)
|
||||
{
|
||||
con->last_recv = time(0);
|
||||
}
|
||||
else if (ret == -1 && (net_error() == EWOULDBLOCK || net_error() == EINTR))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
#ifdef SSL_SUPPORT
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: Not able to do this!
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void net_con_set_timeout(struct net_connection* con, int seconds)
|
||||
{
|
||||
uhub_assert(con);
|
||||
|
||||
@@ -64,6 +64,7 @@ struct net_connection
|
||||
};
|
||||
|
||||
extern void net_con_initialize(struct net_connection* con, int sd, net_connection_cb callback, const void* ptr, int events);
|
||||
extern void net_con_reinitialize(struct net_connection* con, net_connection_cb callback, const void* ptr, int events);
|
||||
extern void net_con_update(struct net_connection* con, int events);
|
||||
|
||||
/**
|
||||
@@ -92,6 +93,13 @@ extern ssize_t net_con_send(struct net_connection* con, const void* buf, size_t
|
||||
*/
|
||||
extern ssize_t net_con_recv(struct net_connection* con, void* buf, size_t len);
|
||||
|
||||
/**
|
||||
* Receive data without removing them from the recv() buffer.
|
||||
* NOTE: This does not currently work for SSL connections after the SSL handshake has been
|
||||
* performed.
|
||||
*/
|
||||
extern ssize_t net_con_peek(struct net_connection* con, void* buf, size_t len);
|
||||
|
||||
/**
|
||||
* Set timeout for connetion.
|
||||
*
|
||||
|
||||
@@ -80,9 +80,14 @@ size_t net_get_max_sockets()
|
||||
}
|
||||
LOG_ERROR("getrlimit() failed");
|
||||
#else
|
||||
LOG_ERROR("System does not have getrlimit(): constrained to 1024 sockets");
|
||||
#endif /* HAVE_GETRLIMIT */
|
||||
#ifdef WIN32
|
||||
LOG_WARN("Windows system, limited to 4096 connections.");
|
||||
return 4096;
|
||||
#else
|
||||
LOG_WARN("System does not have getrlimit(): constrained to 1024 sockets");
|
||||
return 1024;
|
||||
#endif
|
||||
#endif /* HAVE_GETRLIMIT */
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user