summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2023-09-29 09:22:30 -0500
committerDanny Holman <dholman@gymli.org>2023-09-29 09:22:30 -0500
commit27f3d76e8a1c4c4f5e301fa45a33cb095c1c9df5 (patch)
treeacb8e476f44bef3c5cfc41246b9ea047789f55bb
parent98fee7fdd86db5c19d88fe829bc665a75569325d (diff)
server: remove input/output pump functions
Remove the functions doing I/O on socket operations. These functions are designed for single-threaded applications or for non-blocking sockets; neither of which mini-rat has. Signed-off-by: Danny Holman <dholman@gymli.org>
-rw-r--r--server/include/server.h3
-rw-r--r--server/src/server.c33
-rw-r--r--server/src/session.c4
3 files changed, 4 insertions, 36 deletions
diff --git a/server/include/server.h b/server/include/server.h
index 3b39d72..f2f2c23 100644
--- a/server/include/server.h
+++ b/server/include/server.h
@@ -11,7 +11,4 @@ int ping_pong(int sock);
void* listener(void *port);
void* worker(void *sock_desc);
-ssize_t output_pump(int sock, char *buffer, size_t sz);
-ssize_t input_pump(int sock, char *buffer, size_t sz);
-
#endif
diff --git a/server/src/server.c b/server/src/server.c
index bf2ed25..4ed8af9 100644
--- a/server/src/server.c
+++ b/server/src/server.c
@@ -40,14 +40,12 @@ int ping_pong(int sock) {
char buffer[6];
memset(buffer, 0, 6);
- pthread_mutex_lock(&sock_mutex);
- if (output_pump(sock, "PING\r\n", 6) != -1)
+ if (send(sock, "PING\r\n", 6, 0) != -1)
ret = -1;
- if (input_pump(sock, buffer, 6) == -1)
+ if (recv(sock, buffer, 6, 0) == -1)
ret = -1;
if (strncmp(buffer, "PONG\r\n", 6) != 0)
ret = -1;
- pthread_mutex_unlock(&sock_mutex);
return ret;
}
@@ -55,7 +53,6 @@ int ping_pong(int sock) {
void* worker(void *sock_desc) {
int sock = *(int*)sock_desc;
fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) & O_NONBLOCK);
- pthread_mutex_init(&sock_mutex, NULL);
struct session *ses = find_session(init_session(sock));
log_msg(LOG_INFO, "New session created with ID=%d\n", ses->id);
@@ -70,29 +67,3 @@ void* worker(void *sock_desc) {
return 0;
}
-
-ssize_t output_pump(int sock, char *buffer, size_t sz) {
- struct pollfd pfd[1];
- pfd[0].fd = sock;
- pfd[0].events = POLLOUT;
- int status = poll(pfd, 1, 10000);
- if (status < 0)
- return -1;
- else if (pfd[0].revents & POLLOUT)
- return send(sock, buffer, sz, 0);
-
- return 0;
-}
-
-ssize_t input_pump(int sock, char *buffer, size_t sz) {
- struct pollfd pfd[1];
- pfd[0].fd = sock;
- pfd[0].events = POLLIN;
- int status = poll(pfd, 1, 10000);
- if (status < 0)
- return -1;
- else if (pfd[0].revents & POLLIN)
- return recv(sock, buffer, sz, 0);
-
- return 0;
-}
diff --git a/server/src/session.c b/server/src/session.c
index d068d38..713c5cb 100644
--- a/server/src/session.c
+++ b/server/src/session.c
@@ -33,7 +33,7 @@ ssize_t write_session(int id, char *buffer, size_t sz) {
if (ses == NULL)
return -1;
- return output_pump(ses->socket, buffer, sz);
+ return send(ses->socket, buffer, sz, 0);
}
ssize_t read_session(int id, char *buffer, size_t sz) {
@@ -41,7 +41,7 @@ ssize_t read_session(int id, char *buffer, size_t sz) {
if (ses == NULL)
return -1;
- return input_pump(ses->socket, buffer, sz);
+ return recv(ses->socket, buffer, sz, 0);
}
void kill_session(int id) {