I have made a start
I have done some work on opening a socket and waiting for a connection. This can be read line by line and I have started a request struct that it will accept. Also started on some docs. Not much is yet working. I am going to start learning µnit for unit tests: https://nemequ.github.io/munit/
This commit is contained in:
parent
4e17e706fa
commit
f48a110429
15 changed files with 599 additions and 1 deletions
42
src/proxy.c
Normal file
42
src/proxy.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "proxy.h"
|
||||
|
||||
void proxy_startListener(unsigned int port){
|
||||
// https://www.geeksforgeeks.org/socket-programming-cc/
|
||||
int server_fd, new_socket;
|
||||
struct sockaddr_in address;
|
||||
int opt = 1;
|
||||
int addrlen = sizeof(address);
|
||||
char line[1024] = {0};
|
||||
|
||||
// Creating socket file descriptor
|
||||
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
|
||||
perror("socket failed");
|
||||
return ;
|
||||
}
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
address.sin_port = htons( port );
|
||||
|
||||
// Forcefully attaching socket to the port 8080
|
||||
if (bind(server_fd, (struct sockaddr *)&address, sizeof(address))<0) {
|
||||
perror("bind failed");
|
||||
return ;
|
||||
}
|
||||
|
||||
if (listen(server_fd, 3) < 0) {
|
||||
perror("listen");
|
||||
return ;
|
||||
}
|
||||
while ( true ){
|
||||
printf("Listening\n");
|
||||
if ((new_socket = accept(server_fd, (struct sockaddr *)&address,
|
||||
(socklen_t*)&addrlen))<0) {
|
||||
perror("accept");
|
||||
return ;
|
||||
}
|
||||
|
||||
Request *request = newRequestFromSocket(new_socket);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue