hermes

HTTP GET/HEAD-only web server for static content.
git clone https://git.francescosaccone.com/hermes
Log | Files | Refs | README | LICENSE

socket.h (1117B)


      1 #ifndef SOCKET_H
      2 #define SOCKET_H
      3 
      4 /*
      5  * Creates a socket and a local address at the given port, binds them,
      6  * listens for connections and returns the socket file descriptor.
      7  *
      8  * Returns -1 in case of an error and the socket file descriptor otherwise.
      9  */
     10 int
     11 create_socket(unsigned int port);
     12 
     13 /*
     14  * Closes a socket.
     15  */
     16 void
     17 close_socket(int socket_fd);
     18 
     19 /*
     20  * Returns -1 in case of an error and the length of a socket (actually a
     21  * generic file descriptor) otherwise.
     22  */
     23 int
     24 get_socket_size(int socket_fd);
     25 
     26 /* 
     27  * Accepts a connection from the server socket and returns the client socket
     28  * file descriptor.
     29  *
     30  * Returns -1 in case of an error and the socket file descriptor otherwise.
     31  */
     32 int
     33 accept_client(int server_socket_fd);
     34 
     35 /*
     36  * Writes the client request to a buffer.
     37  *
     38  * Returns -1 in case of an error and 0 otherwise.
     39  */
     40 int
     41 read_client_request(int client_socket_fd,
     42                     char *buffer,
     43                     unsigned int buffer_size);
     44 
     45 /*
     46  * Writes data to a socket.
     47  *
     48  * Returns -1 in case of an error and 0 otherwise.
     49  */
     50 int
     51 send_to_socket(int socket_fd, char *data);
     52 
     53 #endif