libamxp  1.4.0
Patterns C Implementation
amxp_connections.c File Reference
#include <string.h>
#include <amxc/amxc_macros.h>
#include <amxc/amxc.h>
#include <amxp/amxp_signal.h>
#include <amxp/amxp_connection.h>

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

static amxp_connection_tamxp_connection_get_internal (amxc_llist_t *list, int fd)
 
static int amxp_can_add_connection (int fd, uint32_t type)
 
static int amxp_connection_add_impl (amxp_connection_t *con, amxp_fd_cb_t reader)
 
static void amxp_connection_free (amxc_llist_it_t *it)
 
int amxp_connection_add (int fd, amxp_fd_cb_t reader, const char *uri, uint32_t type, void *priv)
 Adds a file descriptor (fd) to the list of fds that must be watched. More...
 
int amxp_connection_wait_write (int fd, amxp_fd_cb_t can_write_cb)
 Adds a watcher to check if a fd is ready for write. More...
 
int amxp_connection_remove (int fd)
 Removes the fd from the connection list. More...
 
amxp_connection_tamxp_connection_get (int fd)
 Gets the connection data for a file descriptor. More...
 
amxp_connection_tamxp_connection_get_first (uint32_t type)
 Gets the first connection of the given type. More...
 
amxp_connection_tamxp_connection_get_next (amxp_connection_t *con, uint32_t type)
 Gets the next connection data for a file descriptor. More...
 
int amxp_connection_set_el_data (int fd, void *el_data)
 Sets event-loop data. More...
 
amxc_llist_t * amxp_connection_get_connections (void)
 Get a list of the current connections of the application. More...
 
amxc_llist_t * amxp_connection_get_listeners (void)
 Get of the current listen sockets of the application. More...
 
static DESTRUCTOR void amxp_connection_cleanup (void)
 

Variables

static amxc_llist_t listeners
 
static amxc_llist_t connections
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxp_connections.c.

Function Documentation

◆ amxp_can_add_connection()

static int amxp_can_add_connection ( int  fd,
uint32_t  type 
)
static

Definition at line 84 of file amxp_connections.c.

85  {
86  int retval = -1;
87  amxp_connection_t* con = NULL;
88 
89  if(type == AMXP_CONNECTION_LISTEN) {
91  } else {
93  }
94 
95  retval = con == NULL ? 0 : -1;
96 
97  return retval;
98 }
#define AMXP_CONNECTION_LISTEN
static amxc_llist_t connections
static amxc_llist_t listeners
static amxp_connection_t * amxp_connection_get_internal(amxc_llist_t *list, int fd)

◆ amxp_connection_add_impl()

static int amxp_connection_add_impl ( amxp_connection_t con,
amxp_fd_cb_t  reader 
)
static

Definition at line 100 of file amxp_connections.c.

101  {
102  int retval = -1;
103  amxc_var_t var_fd;
104 
105  amxc_var_init(&var_fd);
106  amxc_var_set(fd_t, &var_fd, con->fd);
107 
108  con->reader = reader;
109  if(con->type == AMXP_CONNECTION_LISTEN) {
110  amxc_llist_append(&listeners, &con->it);
111  amxp_sigmngr_trigger_signal(NULL, "listen-added", &var_fd);
112  } else {
113  amxc_llist_append(&connections, &con->it);
114  amxp_sigmngr_trigger_signal(NULL, "connection-added", &var_fd);
115  }
116 
117  retval = 0;
118 
119  amxc_var_clean(&var_fd);
120  return retval;
121 }
void amxp_sigmngr_trigger_signal(amxp_signal_mngr_t *const sig_mngr, const char *name, const amxc_var_t *const data)
Triggers a signal.
Definition: amxp_signal.c:492
amxc_llist_it_t it
amxp_fd_cb_t reader
static void reader(UNUSED int fd, UNUSED void *priv)

◆ amxp_connection_cleanup()

static DESTRUCTOR void amxp_connection_cleanup ( void  )
static

Definition at line 287 of file amxp_connections.c.

287  {
288  amxc_llist_clean(&connections, amxp_connection_free);
289  amxc_llist_clean(&listeners, amxp_connection_free);
290 }
static void amxp_connection_free(amxc_llist_it_t *it)

◆ amxp_connection_free()

static void amxp_connection_free ( amxc_llist_it_t *  it)
static

Definition at line 123 of file amxp_connections.c.

123  {
124  amxp_connection_t* con = amxc_llist_it_get_data(it, amxp_connection_t, it);
125  free(con->uri);
126  free(con);
127 }

◆ amxp_connection_get_internal()

static amxp_connection_t* amxp_connection_get_internal ( amxc_llist_t *  list,
int  fd 
)
static

Definition at line 69 of file amxp_connections.c.

70  {
71  amxp_connection_t* con = NULL;
72 
73  amxc_llist_for_each(it, list) {
74  con = amxc_llist_it_get_data(it, amxp_connection_t, it);
75  if(con->fd == fd) {
76  break;
77  }
78  con = NULL;
79  }
80 
81  return con;
82 }

Variable Documentation

◆ connections

amxc_llist_t connections
static

Definition at line 67 of file amxp_connections.c.

◆ listeners

amxc_llist_t listeners
static

Definition at line 66 of file amxp_connections.c.