about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2025-04-27 00:05:22 +0300
committerNakidai <nakidai@disroot.org>2025-04-27 00:05:22 +0300
commitcd42113e79b291a9e061aa0f18a231e008a2527b (patch)
tree13892951c18ea8dc267f61b2cbb2d11f5ef7944c
parent28427dfa221475308bb2971d8e3dcae07d13c126 (diff)
downloadttb-cd42113e79b291a9e061aa0f18a231e008a2527b.tar.gz
ttb-cd42113e79b291a9e061aa0f18a231e008a2527b.zip
Fix server socket
Since it is used in poll, no need for it to be non-blocking

Also, accept(2) actually has a lot of error codes, and its return value
should be checked
-rw-r--r--ttb.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/ttb.c b/ttb.c
index 38055a7..d64375d 100644
--- a/ttb.c
+++ b/ttb.c
@@ -38,7 +38,7 @@ int main(int argc, char **argv)
 			err(1, "inet_pton()");
 	}
 
-	peers[0] = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
+	peers[0] = socket(AF_INET, SOCK_STREAM, 0);
 	if (peers[0] == -1)
 		err(1, "socket()");
 
@@ -72,6 +72,11 @@ int main(int argc, char **argv)
 		if (ppeers[0].revents & POLLIN)
 		{
 			int client = accept(peers[0], NULL, NULL);
+			if (client == -1)
+			{
+				warn("accept()");
+				goto after;
+			}
 			for (size_t i = 1; i < lengthof(peers); ++i)
 				if (!peers[i])
 				{