Skip to content

Commit

Permalink
add server_ready file to externally monitor example server for ready …
Browse files Browse the repository at this point in the history
…to accept, -r option
  • Loading branch information
toddouska committed Nov 26, 2014
1 parent 438cb51 commit 1f8d845
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ examples/client/client
examples/echoclient/echoclient
examples/echoserver/echoserver
examples/server/server
server_ready
snifftest
output
mcapi/test
Expand Down
3 changes: 2 additions & 1 deletion IDE/MDK5-ARM/Projects/CyaSSL-Full/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
SetupPkCallbacks(ctx, ssl);
#endif

tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS);
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS,
0);
if (!doDTLS)
CloseSocket(sockfd);

Expand Down
3 changes: 2 additions & 1 deletion IDE/MDK5-ARM/Projects/SimpleServer/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
SetupPkCallbacks(ctx, ssl);
#endif

tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS);
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS,
0);
if (!doDTLS)
CloseSocket(sockfd);

Expand Down
13 changes: 12 additions & 1 deletion cyassl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ static INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,

static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
func_args* args, word16 port, int useAnyAddr,
int udp)
int udp, int ready_file)
{
SOCKADDR_IN_T client;
socklen_t client_len = sizeof(client);
Expand Down Expand Up @@ -727,6 +727,17 @@ static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
ready->port = port;
#endif

if (ready_file) {
#ifndef NO_FILESYSTEM
FILE* srf = fopen("./server_ready", "w+");

if (srf) {
fputs("ready", srf);
fclose(srf);
}
#endif
}

*clientfd = accept(*sockfd, (struct sockaddr*)&client,
(ACCEPT_THIRD_T)&client_len);
#ifdef USE_WINDOWS_API
Expand Down
11 changes: 9 additions & 2 deletions examples/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static void Usage(void)
printf("-u Use UDP DTLS,"
" add -v 2 for DTLSv1 (default), -v 3 for DTLSv1.2\n");
printf("-f Fewer packets/group messages\n");
printf("-r Create server ready file, for external monitor\n");
printf("-N Use Non-blocking sockets\n");
printf("-S <str> Use Host Name Indication\n");
#ifdef HAVE_OCSP
Expand Down Expand Up @@ -166,6 +167,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
int trackMemory = 0;
int fewerPackets = 0;
int pkCallbacks = 0;
int serverReadyFile = 0;
char* cipherList = NULL;
const char* verifyCert = cliCert;
const char* ourCert = svrCert;
Expand Down Expand Up @@ -196,7 +198,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
fdOpenSession(Task_self());
#endif

while ((ch = mygetopt(argc, argv, "?dbstnNufPp:v:l:A:c:k:S:oO:")) != -1) {
while ((ch = mygetopt(argc, argv, "?dbstnNufrPp:v:l:A:c:k:S:oO:")) != -1) {
switch (ch) {
case '?' :
Usage();
Expand Down Expand Up @@ -232,6 +234,10 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
fewerPackets = 1;
break;

case 'r' :
serverReadyFile = 1;
break;

case 'P' :
#ifdef HAVE_PK_CALLBACKS
pkCallbacks = 1;
Expand Down Expand Up @@ -482,7 +488,8 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
SetupPkCallbacks(ctx, ssl);
#endif

tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS);
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS,
serverReadyFile);
if (!doDTLS)
CloseSocket(sockfd);

Expand Down
4 changes: 2 additions & 2 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static THREAD_RETURN CYASSL_THREAD test_server_nofail(void* args)
}

ssl = CyaSSL_new(ctx);
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0);
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0);
CloseSocket(sockfd);

CyaSSL_set_fd(ssl, clientfd);
Expand Down Expand Up @@ -551,7 +551,7 @@ static THREAD_RETURN CYASSL_THREAD run_cyassl_server(void* args)

ssl = CyaSSL_new(ctx);

tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0);
tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0);
CloseSocket(sfd);

CyaSSL_set_fd(ssl, cfd);
Expand Down

0 comments on commit 1f8d845

Please sign in to comment.