Loading tests/server/sockfilt.c +32 −17 Original line number Diff line number Diff line Loading @@ -213,7 +213,8 @@ unsigned short connectport = 0; /* if non-zero, we activate this mode */ enum sockmode { PASSIVE_LISTEN, /* as a server waiting for connections */ PASSIVE_CONNECT, /* as a server, connected to a client */ ACTIVE /* as a client, connected to a server */ ACTIVE, /* as a client, connected to a server */ ACTIVE_DISCONNECT /* as a client, disconnected from server */ }; /* Loading Loading @@ -281,6 +282,12 @@ static int juggle(curl_socket_t *sockfdp, maxfd = 0; } break; case ACTIVE_DISCONNECT: logmsg("disconnected, no socket to read on"); maxfd = 0; sockfd = CURL_SOCKET_BAD; break; } do { Loading Loading @@ -335,7 +342,7 @@ static int juggle(curl_socket_t *sockfdp, else if(!memcmp("QUIT", buffer, 4)) { /* just die */ logmsg("quits"); exit(0); return FALSE; } else if(!memcmp("DATA", buffer, 4)) { /* data IN => data OUT */ Loading Loading @@ -366,6 +373,10 @@ static int juggle(curl_socket_t *sockfdp, logmsg("====> Client forcibly disconnected"); sclose(sockfd); *sockfdp = CURL_SOCKET_BAD; if(*mode == PASSIVE_CONNECT) *mode = PASSIVE_LISTEN; else *mode = ACTIVE_DISCONNECT; } else logmsg("attempt to close already dead connection"); Loading @@ -374,7 +385,7 @@ static int juggle(curl_socket_t *sockfdp, } else { logmsg("read %d from stdin, exiting", (int)nread); exit(0); return FALSE; } } Loading Loading @@ -405,6 +416,8 @@ static int juggle(curl_socket_t *sockfdp, *sockfdp = CURL_SOCKET_BAD; if(*mode == PASSIVE_CONNECT) *mode = PASSIVE_LISTEN; else *mode = ACTIVE_DISCONNECT; return TRUE; } Loading Loading @@ -491,7 +504,7 @@ int main(int argc, char *argv[]) " --ipv4\n" " --ipv6\n" " --port [port]"); exit(0); return 0; } } Loading Loading @@ -522,7 +535,7 @@ int main(int argc, char *argv[]) if (sock < 0) { perror("opening stream socket"); logmsg("Error opening socket"); exit(1); return 1; } if(connectport) { Loading Loading @@ -552,7 +565,7 @@ int main(int argc, char *argv[]) if(rc) { perror("connecting stream socket"); logmsg("Error connecting to port %d", port); exit(1); return 1; } logmsg("====> Client connect"); msgsock = sock; /* use this as stream */ Loading Loading @@ -587,7 +600,7 @@ int main(int argc, char *argv[]) if(rc < 0) { perror("binding stream socket"); logmsg("Error binding socket"); exit(1); return 1; } if(!port) { Loading @@ -610,14 +623,6 @@ int main(int argc, char *argv[]) } pidfile = fopen(pidname, "w"); if(pidfile) { fprintf(pidfile, "%d\n", (int)getpid()); fclose(pidfile); } else fprintf(stderr, "Couldn't write pid file\n"); logmsg("Running IPv%d version", (use_ipv6?6:4)); Loading @@ -626,6 +631,16 @@ int main(int argc, char *argv[]) else logmsg("Listening on port %d", port); pidfile = fopen(pidname, "w"); if(pidfile) { int pid = (int)getpid(); fprintf(pidfile, "%d\n", pid); fclose(pidfile); logmsg("Wrote pid %d to %s", pid, pidname); } else fprintf(stderr, "Couldn't write pid file\n"); do { ok = juggle(&msgsock, sock, &mode); } while(ok); Loading Loading
tests/server/sockfilt.c +32 −17 Original line number Diff line number Diff line Loading @@ -213,7 +213,8 @@ unsigned short connectport = 0; /* if non-zero, we activate this mode */ enum sockmode { PASSIVE_LISTEN, /* as a server waiting for connections */ PASSIVE_CONNECT, /* as a server, connected to a client */ ACTIVE /* as a client, connected to a server */ ACTIVE, /* as a client, connected to a server */ ACTIVE_DISCONNECT /* as a client, disconnected from server */ }; /* Loading Loading @@ -281,6 +282,12 @@ static int juggle(curl_socket_t *sockfdp, maxfd = 0; } break; case ACTIVE_DISCONNECT: logmsg("disconnected, no socket to read on"); maxfd = 0; sockfd = CURL_SOCKET_BAD; break; } do { Loading Loading @@ -335,7 +342,7 @@ static int juggle(curl_socket_t *sockfdp, else if(!memcmp("QUIT", buffer, 4)) { /* just die */ logmsg("quits"); exit(0); return FALSE; } else if(!memcmp("DATA", buffer, 4)) { /* data IN => data OUT */ Loading Loading @@ -366,6 +373,10 @@ static int juggle(curl_socket_t *sockfdp, logmsg("====> Client forcibly disconnected"); sclose(sockfd); *sockfdp = CURL_SOCKET_BAD; if(*mode == PASSIVE_CONNECT) *mode = PASSIVE_LISTEN; else *mode = ACTIVE_DISCONNECT; } else logmsg("attempt to close already dead connection"); Loading @@ -374,7 +385,7 @@ static int juggle(curl_socket_t *sockfdp, } else { logmsg("read %d from stdin, exiting", (int)nread); exit(0); return FALSE; } } Loading Loading @@ -405,6 +416,8 @@ static int juggle(curl_socket_t *sockfdp, *sockfdp = CURL_SOCKET_BAD; if(*mode == PASSIVE_CONNECT) *mode = PASSIVE_LISTEN; else *mode = ACTIVE_DISCONNECT; return TRUE; } Loading Loading @@ -491,7 +504,7 @@ int main(int argc, char *argv[]) " --ipv4\n" " --ipv6\n" " --port [port]"); exit(0); return 0; } } Loading Loading @@ -522,7 +535,7 @@ int main(int argc, char *argv[]) if (sock < 0) { perror("opening stream socket"); logmsg("Error opening socket"); exit(1); return 1; } if(connectport) { Loading Loading @@ -552,7 +565,7 @@ int main(int argc, char *argv[]) if(rc) { perror("connecting stream socket"); logmsg("Error connecting to port %d", port); exit(1); return 1; } logmsg("====> Client connect"); msgsock = sock; /* use this as stream */ Loading Loading @@ -587,7 +600,7 @@ int main(int argc, char *argv[]) if(rc < 0) { perror("binding stream socket"); logmsg("Error binding socket"); exit(1); return 1; } if(!port) { Loading @@ -610,14 +623,6 @@ int main(int argc, char *argv[]) } pidfile = fopen(pidname, "w"); if(pidfile) { fprintf(pidfile, "%d\n", (int)getpid()); fclose(pidfile); } else fprintf(stderr, "Couldn't write pid file\n"); logmsg("Running IPv%d version", (use_ipv6?6:4)); Loading @@ -626,6 +631,16 @@ int main(int argc, char *argv[]) else logmsg("Listening on port %d", port); pidfile = fopen(pidname, "w"); if(pidfile) { int pid = (int)getpid(); fprintf(pidfile, "%d\n", pid); fclose(pidfile); logmsg("Wrote pid %d to %s", pid, pidname); } else fprintf(stderr, "Couldn't write pid file\n"); do { ok = juggle(&msgsock, sock, &mode); } while(ok); Loading