#ifndef __CONNECTION_H #define __CONNECTION_H #include #include // Add socket to managed sockets. // Parameters: // - fd - socket fd // Returns: // - on success: ID of connection (>0) // - on failure: 0 // Remarks: // - in case of success, you may forget about // the socket you added because it is completely // managed by this module // - in case of failure you still need to close // the socket // - does not check if fd is already added uint32_t connection_add(int fd); // Cleanup. // Remarks: // - closes all connections void connection_cleanup(); // Check if socket is managed. // Parameters: // - fd - socket fd // Returns: // - true if the socket is managed // - false if the socket is not managed bool connection_is_socket_managed(int fd); // Handle socket events. // Parameters: // - fd - socket fd // - events - events as returned by epoll_wait // Returns: // - true on success // - false on failure // Remarks: // - you must make sure fd is managed by this module // (use connection_is_socket_managed) // - the app should be terminated if this function returns false void connection_event(int fd, uint32_t events); // Send data over connection. // Parameters: // - id - connection ID // - data - data to send // - size - size of data // Returns: // - count of bytes sent uint32_t connection_send(uint32_t id, const void *data, uint32_t size); #endif