diff options
Diffstat (limited to 'extras/libmemif/src/main.c')
-rw-r--r-- | extras/libmemif/src/main.c | 468 |
1 files changed, 0 insertions, 468 deletions
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c index e70334ae40f..967e033cda3 100644 --- a/extras/libmemif/src/main.c +++ b/extras/libmemif/src/main.c @@ -478,27 +478,6 @@ memif_set_connection_request_timer (struct itimerspec timer) } int -memif_per_thread_set_connection_request_timer (memif_per_thread_main_handle_t - pt_main, - struct itimerspec timer) -{ - libmemif_main_t *lm = (libmemif_main_t *) pt_main; - int err = MEMIF_ERR_SUCCESS; - - lm->arm = timer; - - /* overwrite timer, if already armed */ - if (lm->disconn_slaves != 0) - { - if (timerfd_settime (lm->timerfd, 0, &lm->arm, NULL) < 0) - { - err = memif_syscall_error_handler (errno); - } - } - return err; -} - -int memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name, memif_alloc_t * memif_alloc, memif_realloc_t * memif_realloc, memif_free_t * memif_free) @@ -646,174 +625,6 @@ error: return err; } -int -memif_per_thread_init (memif_per_thread_main_handle_t * pt_main, - void *private_ctx, - memif_control_fd_update_t * on_control_fd_update, - char *app_name, memif_alloc_t * memif_alloc, - memif_realloc_t * memif_realloc, - memif_free_t * memif_free) -{ - memif_err_t err = MEMIF_ERR_SUCCESS; - int i; - libmemif_main_t *lm; - - /* Allocate unique libmemif main */ - if (memif_alloc != NULL) - lm = memif_alloc (sizeof (libmemif_main_t)); - else - lm = malloc (sizeof (libmemif_main_t)); - - if (lm == NULL) - return MEMIF_ERR_NOMEM; - - memset (lm, 0, sizeof (libmemif_main_t)); - - /* register custom memory management */ - if (memif_alloc != NULL) - { - memif_alloc_register (lm, memif_alloc); - } - else - memif_alloc_register (lm, malloc); - - if (memif_realloc != NULL) - { - memif_realloc_register (lm, memif_realloc); - } - else - memif_realloc_register (lm, realloc); - - if (memif_free != NULL) - memif_free_register (lm, memif_free); - else - memif_free_register (lm, free); - - lm->private_ctx = private_ctx; - - /* set app name */ - if (app_name != NULL) - { - strlcpy ((char *) lm->app_name, app_name, MEMIF_NAME_LEN); - } - else - { - strlcpy ((char *) lm->app_name, MEMIF_DEFAULT_APP_NAME, - sizeof (lm->app_name)); - } - - lm->poll_cancel_fd = -1; - /* register control fd update callback */ - if (on_control_fd_update != NULL) - memif_control_fd_update_register (lm, on_control_fd_update); - else - { - /* private_ctx only used internally by memif_control_fd_update - * pointer to this libmemif main - */ - lm->private_ctx = lm; - lm->epfd = epoll_create (1); - memif_control_fd_update_register (lm, memif_control_fd_update); - if ((lm->poll_cancel_fd = eventfd (0, EFD_NONBLOCK)) < 0) - { - err = errno; - DBG ("eventfd: %s", strerror (err)); - return memif_syscall_error_handler (err); - } - lm->control_fd_update (lm->poll_cancel_fd, MEMIF_FD_EVENT_READ, - lm->private_ctx); - DBG ("libmemif event polling initialized"); - } - - /* Initialize lists */ - lm->control_list_len = 2; - lm->interrupt_list_len = 2; - lm->socket_list_len = 1; - lm->pending_list_len = 1; - - lm->control_list = - lm->alloc (sizeof (memif_list_elt_t) * lm->control_list_len); - if (lm->control_list == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - lm->interrupt_list = - lm->alloc (sizeof (memif_list_elt_t) * lm->interrupt_list_len); - if (lm->interrupt_list == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - lm->socket_list = - lm->alloc (sizeof (memif_list_elt_t) * lm->socket_list_len); - if (lm->socket_list == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - lm->pending_list = - lm->alloc (sizeof (memif_list_elt_t) * lm->pending_list_len); - if (lm->pending_list == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - - for (i = 0; i < lm->control_list_len; i++) - { - lm->control_list[i].key = -1; - lm->control_list[i].data_struct = NULL; - } - for (i = 0; i < lm->interrupt_list_len; i++) - { - lm->interrupt_list[i].key = -1; - lm->interrupt_list[i].data_struct = NULL; - } - for (i = 0; i < lm->socket_list_len; i++) - { - lm->socket_list[i].key = -1; - lm->socket_list[i].data_struct = NULL; - } - for (i = 0; i < lm->pending_list_len; i++) - { - lm->pending_list[i].key = -1; - lm->pending_list[i].data_struct = NULL; - } - - /* Initialize autoconnect */ - lm->disconn_slaves = 0; - - lm->timerfd = timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK); - if (lm->timerfd < 0) - { - err = memif_syscall_error_handler (errno); - goto error; - } - - lm->arm.it_value.tv_sec = MEMIF_DEFAULT_RECONNECT_PERIOD_SEC; - lm->arm.it_value.tv_nsec = MEMIF_DEFAULT_RECONNECT_PERIOD_NSEC; - lm->arm.it_interval.tv_sec = MEMIF_DEFAULT_RECONNECT_PERIOD_SEC; - lm->arm.it_interval.tv_nsec = MEMIF_DEFAULT_RECONNECT_PERIOD_NSEC; - - if (lm->control_fd_update (lm->timerfd, MEMIF_FD_EVENT_READ, - lm->private_ctx) < 0) - { - DBG ("callback type memif_control_fd_update_t error!"); - err = MEMIF_ERR_CB_FDUPDATE; - goto error; - } - - *pt_main = lm; - - return err; - -error: - *pt_main = lm; - memif_per_thread_cleanup (pt_main); - return err; -} - static inline memif_ring_t * memif_get_ring (memif_connection_t * conn, memif_ring_type_t type, uint16_t ring_num) @@ -988,78 +799,6 @@ error: return err; } -int -memif_per_thread_create_socket (memif_per_thread_main_handle_t pt_main, - memif_socket_handle_t * sock, - const char *filename, void *private_ctx) -{ - libmemif_main_t *lm = (libmemif_main_t *) pt_main; - memif_socket_t *ms = (memif_socket_t *) * sock; - int i, err = MEMIF_ERR_SUCCESS; - - if (lm == NULL) - return MEMIF_ERR_INVAL_ARG; - - for (i = 0; i < lm->socket_list_len; i++) - { - if ((ms = (memif_socket_t *) lm->socket_list[i].data_struct) != NULL) - { - if (strncmp ((char *) ms->filename, filename, - strlen ((char *) ms->filename)) == 0) - return MEMIF_ERR_INVAL_ARG; - } - } - - /* allocate memif_socket_t */ - ms = NULL; - ms = lm->alloc (sizeof (memif_socket_t)); - if (ms == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - memset (ms, 0, sizeof (memif_socket_t)); - ms->lm = lm; - /* set filename */ - memset (ms->filename, 0, sizeof (ms->filename)); - strlcpy ((char *) ms->filename, filename, sizeof (ms->filename)); - - ms->type = MEMIF_SOCKET_TYPE_NONE; - - ms->interface_list_len = 1; - ms->interface_list = - lm->alloc (sizeof (memif_list_elt_t) * ms->interface_list_len); - if (ms->interface_list == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - ms->interface_list[0].key = -1; - ms->interface_list[0].data_struct = NULL; - - *sock = ms; - - return err; - -error: - if (ms != NULL) - { - if (ms->fd > 0) - { - close (ms->fd); - ms->fd = -1; - } - if (ms->interface_list != NULL) - { - lm->free (ms->interface_list); - ms->interface_list = NULL; - ms->interface_list_len = 0; - } - lm->free (ms); - *sock = ms = NULL; - } - return err; -} int memif_create (memif_conn_handle_t * c, memif_conn_args_t * args, @@ -1385,119 +1124,6 @@ error: return err; } -int -memif_per_thread_control_fd_handler (memif_per_thread_main_handle_t pt_main, - int fd, uint8_t events) -{ - int i, err = MEMIF_ERR_SUCCESS; /* 0 */ - uint16_t num; - memif_list_elt_t *e = NULL; - memif_connection_t *conn; - libmemif_main_t *lm = (libmemif_main_t *) pt_main; - - if (fd == lm->timerfd) - { - uint64_t b; - ssize_t size; - size = read (fd, &b, sizeof (b)); - - if (size == -1) - goto error; - - for (i = 0; i < lm->control_list_len; i++) - { - if ((lm->control_list[i].key < 0) - && (lm->control_list[i].data_struct != NULL)) - { - conn = lm->control_list[i].data_struct; - if (conn->args.is_master) - continue; - err = memif_request_connection (conn); - if (err != MEMIF_ERR_SUCCESS) - DBG ("memif_request_connection: %s", memif_strerror (err)); - } - } - } - else - { - get_list_elt (&e, lm->interrupt_list, lm->interrupt_list_len, fd); - if (e != NULL) - { - if (((memif_connection_t *) e->data_struct)->on_interrupt != NULL) - { - num = - (((memif_connection_t *) e->data_struct)-> - args.is_master) ? ((memif_connection_t *) e-> - data_struct)->run_args. - num_s2m_rings : ((memif_connection_t *) e->data_struct)-> - run_args.num_m2s_rings; - for (i = 0; i < num; i++) - { - if (((memif_connection_t *) e->data_struct)-> - rx_queues[i].int_fd == fd) - { - ((memif_connection_t *) e->data_struct)-> - on_interrupt ((void *) e->data_struct, - ((memif_connection_t *) e-> - data_struct)->private_ctx, i); - return MEMIF_ERR_SUCCESS; - } - } - } - return MEMIF_ERR_SUCCESS; - } - get_list_elt (&e, lm->socket_list, lm->socket_list_len, fd); - if (e != NULL - && ((memif_socket_t *) e->data_struct)->type == - MEMIF_SOCKET_TYPE_LISTENER) - { - err = - memif_conn_fd_accept_ready ((memif_socket_t *) e->data_struct); - return err; - } - - get_list_elt (&e, lm->pending_list, lm->pending_list_len, fd); - if (e != NULL) - { - err = memif_read_ready (lm, fd); - return err; - } - - get_list_elt (&e, lm->control_list, lm->control_list_len, fd); - if (e != NULL) - { - if (events & MEMIF_FD_EVENT_READ) - { - err = - ((memif_connection_t *) e->data_struct)-> - read_fn (e->data_struct); - if (err != MEMIF_ERR_SUCCESS) - return err; - } - if (events & MEMIF_FD_EVENT_WRITE) - { - err = - ((memif_connection_t *) e->data_struct)-> - write_fn (e->data_struct); - if (err != MEMIF_ERR_SUCCESS) - return err; - } - if (events & MEMIF_FD_EVENT_ERROR) - { - err = - ((memif_connection_t *) e->data_struct)-> - error_fn (e->data_struct); - if (err != MEMIF_ERR_SUCCESS) - return err; - } - } - } - - return MEMIF_ERR_SUCCESS; /* 0 */ - -error: - return err; -} int memif_poll_event (int timeout) @@ -1542,49 +1168,6 @@ memif_poll_event (int timeout) } int -memif_per_thread_poll_event (memif_per_thread_main_handle_t pt_main, - int timeout) -{ - libmemif_main_t *lm = (libmemif_main_t *) pt_main; - struct epoll_event evt; - int en = 0, err = MEMIF_ERR_SUCCESS; /* 0 */ - uint32_t events = 0; - uint64_t counter = 0; - ssize_t r = 0; - memset (&evt, 0, sizeof (evt)); - evt.events = EPOLLIN | EPOLLOUT; - sigset_t sigset; - sigemptyset (&sigset); - en = epoll_pwait (lm->epfd, &evt, 1, timeout, &sigset); - if (en < 0) - { - err = errno; - DBG ("epoll_pwait: %s", strerror (err)); - return memif_syscall_error_handler (err); - } - if (en > 0) - { - if (evt.data.fd == lm->poll_cancel_fd) - { - r = read (evt.data.fd, &counter, sizeof (counter)); - if (r == -1) - return MEMIF_ERR_DISCONNECTED; - - return MEMIF_ERR_POLL_CANCEL; - } - if (evt.events & EPOLLIN) - events |= MEMIF_FD_EVENT_READ; - if (evt.events & EPOLLOUT) - events |= MEMIF_FD_EVENT_WRITE; - if (evt.events & EPOLLERR) - events |= MEMIF_FD_EVENT_ERROR; - err = memif_control_fd_handler (evt.data.fd, events); - return err; - } - return 0; -} - -int memif_cancel_poll_event () { libmemif_main_t *lm = &libmemif_main; @@ -1600,25 +1183,6 @@ memif_cancel_poll_event () return 0; } -int -memif_per_thread_cancel_poll_event (memif_per_thread_main_handle_t pt_main) -{ - libmemif_main_t *lm = (libmemif_main_t *) pt_main; - uint64_t counter = 1; - ssize_t w = 0; - - if (lm == NULL) - return MEMIF_ERR_INVAL_ARG; - - if (lm->poll_cancel_fd == -1) - return 0; - w = write (lm->poll_cancel_fd, &counter, sizeof (counter)); - if (w < sizeof (counter)) - return MEMIF_ERR_INT_WRITE; - - return 0; -} - static void memif_msg_queue_free (libmemif_main_t * lm, memif_msg_queue_elt_t ** e) { @@ -2844,35 +2408,3 @@ memif_cleanup () return MEMIF_ERR_SUCCESS; /* 0 */ } - -int -memif_per_thread_cleanup (memif_per_thread_main_handle_t * pt_main) -{ - libmemif_main_t *lm = (libmemif_main_t *) * pt_main; - - if (lm == NULL) - return MEMIF_ERR_INVAL_ARG; - - /* No default socket in case of per thread */ - - if (lm->control_list) - lm->free (lm->control_list); - lm->control_list = NULL; - if (lm->interrupt_list) - lm->free (lm->interrupt_list); - lm->interrupt_list = NULL; - if (lm->socket_list) - lm->free (lm->socket_list); - lm->socket_list = NULL; - if (lm->pending_list) - lm->free (lm->pending_list); - lm->pending_list = NULL; - if (lm->poll_cancel_fd != -1) - close (lm->poll_cancel_fd); - - lm->free (lm); - - *pt_main = NULL; - - return MEMIF_ERR_SUCCESS; /* 0 */ -} |