add socket_deferaccept
This commit is contained in:
parent
68d88f60b9
commit
22f88f6550
1
CHANGES
1
CHANGES
@ -1,6 +1,7 @@
|
||||
0.27:
|
||||
add fmt_strm
|
||||
add iob_addbuf_munmap
|
||||
add socket_deferaccept
|
||||
|
||||
0.26:
|
||||
fix really pathological case where io_timeouted would never
|
||||
|
11
socket.h
11
socket.h
@ -50,6 +50,17 @@ int socket_mchopcount6(int s,char hops);
|
||||
int socket_mcloop4(int s,char hops);
|
||||
int socket_mcloop6(int s,char hops);
|
||||
|
||||
/* please note that these are platform specific. Do not expect them to
|
||||
* work. You might still get an accept() signalled even though there is
|
||||
* no data available. So far, DATAIN is supported on FreeBSD and Linux,
|
||||
* and HTTPIN is supported on FreeBSD. */
|
||||
enum defermode {
|
||||
DATAIN, // only signal accept() if there is data coming in
|
||||
HTTPIN, // only signal accept() if a HTTP header has come in
|
||||
};
|
||||
|
||||
void socket_deferaccept(int s,enum defermode mode);
|
||||
|
||||
void socket_tryreservein(int s,int size);
|
||||
|
||||
const char* socket_getifname(uint32 _interface);
|
||||
|
19
socket/socket_deferaccept.c
Normal file
19
socket/socket_deferaccept.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include "socket.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <string.h>
|
||||
|
||||
void socket_deferaccept(int s,enum defermode mode) {
|
||||
#ifdef TCP_DEFER_ACCEPT
|
||||
int one=1;
|
||||
setsockopt(s,IPPROTO_TCP,TCP_DEFER_ACCEPT,&one,sizeof(one));
|
||||
#elif defined(SO_ACCEPTFILTER)
|
||||
struct accept_filter_arg afa;
|
||||
memset(&afa,0,sizeof(afa));
|
||||
strcpy(afa.af_name,mode==HTTPIN?"httpreader":"dataready");
|
||||
setsockopt(sok, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa));
|
||||
#endif
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user