Skip to content

Commit 297705b

Browse files
committed
Report failure from the custom io file client and server
1 parent 79d1f67 commit 297705b

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

custom-io-callbacks/file-client/file-client.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ int main(int argc, char** argv)
172172
char msg[] = "Hello wolfSSL\r\n";
173173
char reply[MAXSZ];
174174
int ret, msgSz;
175+
int rc = -1;
175176
WOLFSSL* sslCli;
176177
WOLFSSL_CTX* ctxCli = NULL;
177178

@@ -242,6 +243,7 @@ int main(int argc, char** argv)
242243
else {
243244
reply[ret] = '\0';
244245
printf("Client Received Reply: %s\n", reply);
246+
rc = 0;
245247
break;
246248
}
247249

@@ -263,5 +265,5 @@ int main(int argc, char** argv)
263265
close(open(CR, O_RDWR | O_NOCTTY | O_NDELAY));
264266
close(open(SR, O_RDWR | O_NOCTTY | O_NDELAY));
265267

266-
return -1;
268+
return rc;
267269
}
Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
#!/bin/sh
2+
3+
# Start the server first: the client's first write must not race an absent reader.
24
./start-server $1 &
3-
PID1=$!
4-
RESULT1=$?
5+
SERVER_PID=$!
56

6-
cd ../file-client
7+
cd ../file-client || exit 1
78
./start-client $1
8-
PID2=$!
9-
RESULT2=$?
9+
CLIENT_RESULT=$?
10+
cd ../file-server || exit 1
11+
12+
# Bound the wait. A failed client leaves the server blocked reading a fifo that
13+
# will never deliver, and a bare `wait` would hang until the CI step times out.
14+
i=0
15+
while kill -0 "${SERVER_PID}" 2>/dev/null && [ "$i" -lt 30 ]; do
16+
sleep 1
17+
i=$((i + 1))
18+
done
19+
20+
if kill -0 "${SERVER_PID}" 2>/dev/null; then
21+
echo "server still running after ${i}s; killing it"
22+
kill "${SERVER_PID}" 2>/dev/null
23+
SERVER_RESULT=1
24+
else
25+
wait "${SERVER_PID}"
26+
SERVER_RESULT=$?
27+
fi
1028

11-
echo "RESULT1 = ${RESULT1}"
12-
echo ""
13-
echo "RESULT2 = ${RESULT2}"
14-
echo ""
15-
kill ${PID1}
16-
kill ${PID2}
29+
echo "server exited ${SERVER_RESULT}"
30+
echo "client exited ${CLIENT_RESULT}"
1731

32+
[ ${CLIENT_RESULT} -eq 0 ] && [ ${SERVER_RESULT} -eq 0 ]

custom-io-callbacks/file-server/file-server.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ int main(int argc, char** argv)
162162
char sMsg[] = "I hear you fashizzle\r\n";
163163
char reply[MAXSZ];
164164
int ret, msgSz;
165+
int rc = -1;
165166
WOLFSSL* sslServ;
166167
WOLFSSL_CTX* ctxServ = NULL;
167168

@@ -185,7 +186,7 @@ int main(int argc, char** argv)
185186
// sslServ = Server(&ctxServ, "ECDHE-RSA-AES128-SHA", 1);
186187
sslServ = Server(&ctxServ, "let-wolfssl-choose", 0);
187188

188-
if (sslServ == NULL) { printf("sslServ NULL\n"); return 0;}
189+
if (sslServ == NULL) { printf("sslServ NULL\n"); return -1;}
189190
ret = SSL_FAILURE;
190191
printf("Starting server\n");
191192
while (ret != SSL_SUCCESS) {
@@ -216,7 +217,7 @@ int main(int argc, char** argv)
216217
if (error != SSL_ERROR_WANT_READ &&
217218
error != SSL_ERROR_WANT_WRITE) {
218219
printf("server read failed\n");
219-
break;
220+
goto cleanup;
220221
}
221222
}
222223
else {
@@ -241,6 +242,7 @@ int main(int argc, char** argv)
241242
}
242243
} else if (ret == msgSz) {
243244
printf("Server send successful\n");
245+
rc = 0;
244246
break;
245247
} else {
246248
printf("Unkown error occurred, shutting down\n");
@@ -272,5 +274,5 @@ int main(int argc, char** argv)
272274
if (f != NULL) fclose(f);
273275
}
274276

275-
return -1;
277+
return rc;
276278
}

0 commit comments

Comments
 (0)