summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-06-30 12:50:29 +0200
committercashmere <cashmere@autistici.org>2026-06-30 12:50:29 +0200
commited648a83def7218a935d27e96e9e1c53a70e1239 (patch)
treee079a1542461a525591047077b3673b152be884d /src/main.c
parent0ebd503c15915fb7d72d28888b0d7ed050a198bd (diff)
downloadtelnet-ed648a83def7218a935d27e96e9e1c53a70e1239.tar.gz
src/main.c: add function descriptions
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 22b5e98..103ca2d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,7 +5,7 @@
#include <unistd.h>
// returns a socket file descriptor.
-// if connection could not be established, 1 gets returned
+// if connection could not be established, -1 gets returned
int establish_connection(struct sockaddr_in addr) {
int sfd = socket(AF_INET, SOCK_STREAM, 0);
if (sfd == -1) {
@@ -29,6 +29,8 @@ int establish_connection(struct sockaddr_in addr) {
return sfd;
}
+// handles new telnet connections.
+// returns 0 on success and -1 on failure.
int handle_new_connection(int sfd, struct pollfd *fds, nfds_t *nfds) {
int conn = accept(sfd, NULL, NULL);
if (conn == -1)
@@ -39,6 +41,8 @@ int handle_new_connection(int sfd, struct pollfd *fds, nfds_t *nfds) {
return 0;
}
+// process message to all the connected clients.
+// returns 0 on success and -1 on failure.
int process_message(struct pollfd *fds, nfds_t *nfds) {
for (nfds_t i = 1; i < *nfds; i++) {
/* if client has something to say */