add -naccept <n> option to s_server to automatically exit after <n> connections
[openssl.git] / apps / s_socket.c
index 6dd736af01f2e09359bc3bfa44c28cf3f1cbe2b8..f73f1931e50529a0495b354aab8dac9410c25acf 100644 (file)
@@ -280,7 +280,7 @@ static int init_client_ip(int *sock, const unsigned char ip[4], int port,
        return(1);
        }
 
-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
+int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context, int naccept)
        {
        int sock;
        char *name = NULL;
@@ -310,7 +310,9 @@ int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, uns
                if (name != NULL) OPENSSL_free(name);
                if (type==SOCK_STREAM)
                        SHUTDOWN2(sock);
-               if (i < 0)
+               if (naccept != -1)
+                       naccept--;
+               if (i < 0 || naccept == 0)
                        {
                        SHUTDOWN2(accept_socket);
                        return(i);