Files
ipoim/connection.h
Nikita Tyukalov, ASUS, Linux 93c83dc40f Fixes
- Removed void* arithmetic
- Fixed connection_send does not return anything
- Fixed server_events invalid args in main.c (and changed its
  declaration)
2026-03-25 01:13:23 +03:00

58 lines
1.4 KiB
C

#ifndef __CONNECTION_H
#define __CONNECTION_H
#include <stdbool.h>
#include <stdint.h>
// 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