aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Pesch <inolen@gmail.com>2013-08-18 10:09:13 -0700
committerAnthony Pesch <inolen@gmail.com>2013-08-18 10:09:13 -0700
commit1cc24592558669e1816b7458eb48e7202f50deb9 (patch)
tree143e0d94c07eedb7ed9495fb78bce604ab1fd90f
parent2dc7b87600df12ff7cf6cabe42cd4c9d251d44de (diff)
clean up sv sockets for socket tests
-rw-r--r--tests/sockets/test_sockets_echo_server.c8
-rw-r--r--tests/sockets/test_sockets_partial_server.c24
2 files changed, 19 insertions, 13 deletions
diff --git a/tests/sockets/test_sockets_echo_server.c b/tests/sockets/test_sockets_echo_server.c
index 8a48b878..38e27cac 100644
--- a/tests/sockets/test_sockets_echo_server.c
+++ b/tests/sockets/test_sockets_echo_server.c
@@ -37,6 +37,11 @@ typedef struct {
server_t server;
client_t client;
+void cleanup() {
+ if (server.fd) close(server.fd);
+ if (client.fd) close(client.fd);
+}
+
void main_loop(void *arg) {
int res;
fd_set fdr;
@@ -105,6 +110,9 @@ int main() {
struct sockaddr_in addr;
int res;
+ atexit(cleanup);
+ signal(SIGTERM, cleanup);
+
memset(&server, 0, sizeof(server_t));
memset(&client, 0, sizeof(client_t));
diff --git a/tests/sockets/test_sockets_partial_server.c b/tests/sockets/test_sockets_partial_server.c
index 57fae84b..dfe0e249 100644
--- a/tests/sockets/test_sockets_partial_server.c
+++ b/tests/sockets/test_sockets_partial_server.c
@@ -14,18 +14,13 @@
#include <emscripten.h>
#endif
-int serverfd = -1;
-int clientfd = -1;
-
-// csock.send("\x09\x01\x02\x03\x04\x05\x06\x07\x08\x09")
-// csock.send("\x08\x01\x02\x03\x04\x05\x06\x07\x08")
-// csock.send("\x07\x01\x02\x03\x04\x05\x06\x07")
-// csock.send("\x06\x01\x02\x03\x04\x05\x06")
-// csock.send("\x05\x01\x02\x03\x04\x05")
-// csock.send("\x04\x01\x02\x03\x04")
-// csock.send("\x03\x01\x02\x03")
-// csock.send("\x02\x01\x02")
-// csock.send("\x01\x01")
+int serverfd = 0;
+int clientfd = 0;
+
+void cleanup() {
+ if (serverfd) close(serverfd);
+ if (clientfd) close(clientfd);
+}
void do_send(int sockfd) {
static char* buffers[] = {
@@ -69,7 +64,7 @@ void iter(void *arg) {
FD_ZERO(&fdr);
FD_ZERO(&fdw);
FD_SET(serverfd, &fdr);
- if (clientfd != -1) FD_SET(clientfd, &fdw);
+ if (clientfd) FD_SET(clientfd, &fdw);
res = select(64, &fdr, &fdw, NULL, NULL);
if (res == -1) {
perror("select failed");
@@ -91,6 +86,9 @@ int main() {
struct sockaddr_in addr;
int res;
+ atexit(cleanup);
+ signal(SIGTERM, cleanup);
+
// create the socket
serverfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (serverfd == -1) {