summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2012-11-18 15:45:16 +0000
committerDr. Stephen Henson <steve@openssl.org>2013-08-19 17:42:02 +0100
commit95c1a248530e8acf040948dc0a2f82493ed54fc4 (patch)
tree88ca3f0291529861290ed170158af977aab0ee9a /apps
parent08374de10f1cefc02122368c91b0cf4aff791f25 (diff)
add -naccept <n> option to s_server to automatically exit after <n> connections
(cherry picked from commit b5cadfb564a604c0ba1c49984ac796cfd8310731)
Diffstat (limited to 'apps')
-rw-r--r--apps/s_apps.h2
-rw-r--r--apps/s_server.c19
-rw-r--r--apps/s_socket.c6
3 files changed, 20 insertions, 7 deletions
diff --git a/apps/s_apps.h b/apps/s_apps.h
index 64f06090a5..be985280c9 100644
--- a/apps/s_apps.h
+++ b/apps/s_apps.h
@@ -148,7 +148,7 @@ typedef fd_mask fd_set;
#define PORT_STR "4433"
#define PROTOCOL "tcp"
-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);
#ifdef HEADER_X509_H
int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
#endif
diff --git a/apps/s_server.c b/apps/s_server.c
index b67ab4128e..2f3f192985 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -973,7 +973,7 @@ int MAIN(int argc, char *argv[])
STACK_OF(X509) *s_chain = NULL, *s_dchain = NULL;
EVP_PKEY *s_key = NULL, *s_dkey = NULL;
int no_cache = 0, ext_cache = 0;
- int rev = 0;
+ int rev = 0, naccept = -1;
#ifndef OPENSSL_NO_TLSEXT
EVP_PKEY *s_key2 = NULL;
X509 *s_cert2 = NULL;
@@ -1040,6 +1040,17 @@ int MAIN(int argc, char *argv[])
if (!extract_port(*(++argv),&port))
goto bad;
}
+ else if (strcmp(*argv,"-naccept") == 0)
+ {
+ if (--argc < 1) goto bad;
+ naccept = atol(*(++argv));
+ if (naccept <= 0)
+ {
+ BIO_printf(bio_err, "bad accept value %s\n",
+ *argv);
+ goto bad;
+ }
+ }
else if (strcmp(*argv,"-verify") == 0)
{
s_server_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
@@ -1967,11 +1978,11 @@ bad:
BIO_printf(bio_s_out,"ACCEPT\n");
(void)BIO_flush(bio_s_out);
if (rev)
- do_server(port,socket_type,&accept_socket,rev_body, context);
+ do_server(port,socket_type,&accept_socket,rev_body, context, naccept);
else if (www)
- do_server(port,socket_type,&accept_socket,www_body, context);
+ do_server(port,socket_type,&accept_socket,www_body, context, naccept);
else
- do_server(port,socket_type,&accept_socket,sv_body, context);
+ do_server(port,socket_type,&accept_socket,sv_body, context, naccept);
print_stats(bio_s_out,ctx);
ret=0;
end:
diff --git a/apps/s_socket.c b/apps/s_socket.c
index 380efdb1b9..a80f380ad0 100644
--- a/apps/s_socket.c
+++ b/apps/s_socket.c
@@ -284,7 +284,7 @@ static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
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;
@@ -314,7 +314,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);