This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
208 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// vim: set ft=c: | ||
|
||
#include "::/Adam/Net/Socket" | ||
|
||
#define PORT 8000 | ||
|
||
I64 TcpEchoServer() { | ||
SocketInit(); | ||
|
||
I64 sock = socket(AF_INET, SOCK_STREAM); | ||
|
||
if (sock < 0) | ||
return -1; | ||
|
||
sockaddr_in addr; | ||
addr.sin_family = AF_INET; | ||
addr.sin_port = htons(PORT); | ||
addr.sin_addr.s_addr = INADDR_ANY; | ||
|
||
if (bind(sock, &addr, sizeof(addr)) < 0) { | ||
close(sock); | ||
"$FG,4$TcpEchoServer: failed to bind to port %d\n$FG$", PORT; | ||
return -1; | ||
} | ||
|
||
I64 error = listen(sock, 1); | ||
|
||
if (error < 0) { | ||
"$FG,6$listen: error %d\n$FG$", error; | ||
return -1; | ||
} | ||
|
||
"$FG,2$Listening on port %d\n$FG$", PORT; | ||
|
||
I64 client = accept(sock, 0, 0); | ||
|
||
U8 buffer[2048 + 1]; | ||
I64 count = recv(client, buffer, sizeof(buffer) - 1, 0); | ||
|
||
if (count <= 0) { | ||
"$FG,6$recv: error %d\n$FG$", count; | ||
} | ||
else { | ||
buffer[count] = 0; | ||
"$FG,8$Received %d bytes:\n$FG$%s\n", count, buffer; | ||
} | ||
|
||
send(client, buffer, count, 0); | ||
|
||
close(client); | ||
|
||
close(sock); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Submodule TempleOS
updated
from f75b59 to f68cf7