Implemented basic connection logic
This commit is contained in:
19
server.c
19
server.c
@@ -10,6 +10,9 @@
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "connection.h"
|
||||
#include "utils.h"
|
||||
|
||||
/*
|
||||
* Macros
|
||||
*/
|
||||
@@ -24,7 +27,21 @@ static int _fd = -1;
|
||||
* Private API
|
||||
*/
|
||||
bool _accept() {
|
||||
close(accept(_fd, 0, 0));
|
||||
int fd = accept(_fd, 0, 0);
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "[!] accept failed: %d\n", errno);
|
||||
return false;
|
||||
}
|
||||
uint32_t id = connection_add(fd);
|
||||
if (!id) {
|
||||
close(fd);
|
||||
fprintf(stderr, "[!] connection_add failed\n");
|
||||
// no returning false, because it would terminate the app
|
||||
}
|
||||
else {
|
||||
const char* data = "Test data lalalala";
|
||||
connection_send(id, data, strlen(data));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user