X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=extras%2Flibmemif%2Fsrc%2Fsocket.c;h=41bb22b570d4c4cb678dcdaa93d4040fc8830f88;hb=f31acfafb2e78841c0cc1813ddf787829d7f937d;hp=e1c3bd4a257affe2fe4cf4cabc8854d533b526e3;hpb=8f554b793c68fd5271334bf0e167dabc4c9ac73d;p=vpp.git diff --git a/extras/libmemif/src/socket.c b/extras/libmemif/src/socket.c index e1c3bd4a257..41bb22b570d 100644 --- a/extras/libmemif/src/socket.c +++ b/extras/libmemif/src/socket.c @@ -71,7 +71,7 @@ memif_msg_send (int fd, memif_msg_t * msg, int afd) static_fn int memif_msg_enq_ack (memif_connection_t * c) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_msg_queue_elt_t *e = (memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t)); if (e == NULL) @@ -99,9 +99,8 @@ memif_msg_enq_ack (memif_connection_t * c) } static_fn int -memif_msg_send_hello (int fd) +memif_msg_send_hello (libmemif_main_t * lm, int fd) { - libmemif_main_t *lm = &libmemif_main; memif_msg_t msg = { 0 }; memif_msg_hello_t *h = &msg.hello; msg.type = MEMIF_MSG_TYPE_HELLO; @@ -124,7 +123,7 @@ memif_msg_send_hello (int fd) static_fn int memif_msg_enq_init (memif_connection_t * c) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_msg_queue_elt_t *e = (memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t)); if (e == NULL) @@ -166,7 +165,7 @@ memif_msg_enq_init (memif_connection_t * c) static_fn int memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_region_t *mr = &c->regions[region_index]; memif_msg_queue_elt_t *e = @@ -203,7 +202,7 @@ memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index) static_fn int memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_msg_queue_elt_t *e = (memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t)); if (e == NULL) @@ -250,7 +249,7 @@ memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir) static_fn int memif_msg_enq_connect (memif_connection_t * c) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_msg_queue_elt_t *e = (memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t)); if (e == NULL) @@ -285,7 +284,7 @@ memif_msg_enq_connect (memif_connection_t * c) static_fn int memif_msg_enq_connected (memif_connection_t * c) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_msg_queue_elt_t *e = (memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t)); if (e == NULL) @@ -371,10 +370,11 @@ memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg) memif_list_elt_t *elt = NULL; memif_list_elt_t elt2; memif_connection_t *c = NULL; - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (ms); uint8_t err_string[96]; memset (err_string, 0, sizeof (char) * 96); int err = MEMIF_ERR_SUCCESS; /* 0 */ + if (i->version != MEMIF_VERSION) { DBG ("MEMIF_VER_ERR"); @@ -464,14 +464,14 @@ memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg) elt2.key = c->fd; elt2.data_struct = c; - add_list_elt (&elt2, &lm->control_list, &lm->control_list_len); + add_list_elt (lm, &elt2, &lm->control_list, &lm->control_list_len); free_list_elt (lm->pending_list, lm->pending_list_len, fd); return err; error: memif_msg_send_disconnect (fd, err_string, 0); - lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL); + lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL, lm->private_ctx); free_list_elt (lm->pending_list, lm->pending_list_len, fd); close (fd); fd = -1; @@ -483,7 +483,7 @@ static_fn int memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg, int fd) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_msg_add_region_t *ar = &msg->add_region; memif_region_t *mr; @@ -517,7 +517,7 @@ memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg, static_fn int memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_msg_add_ring_t *ar = &msg->add_ring; @@ -580,7 +580,7 @@ static_fn int memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg) { memif_msg_connect_t *cm = &msg->connect; - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); memif_list_elt_t elt; int err; @@ -598,9 +598,11 @@ memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg) { elt.key = c->rx_queues[i].int_fd; elt.data_struct = c; - add_list_elt (&elt, &lm->interrupt_list, &lm->interrupt_list_len); + add_list_elt (lm, &elt, &lm->interrupt_list, + &lm->interrupt_list_len); - lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ); + lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ, + lm->private_ctx); } } @@ -615,7 +617,7 @@ static_fn int memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg) { memif_msg_connect_t *cm = &msg->connect; - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); int err; err = memif_connect1 (c); @@ -630,7 +632,8 @@ memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg) { for (i = 0; i < c->run_args.num_s2m_rings; i++) { - lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ); + lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ, + lm->private_ctx); } } @@ -656,7 +659,7 @@ memif_msg_receive_disconnect (memif_connection_t * c, memif_msg_t * msg) } static_fn int -memif_msg_receive (int ifd) +memif_msg_receive (libmemif_main_t * lm, int ifd) { char ctl[CMSG_SPACE (sizeof (int)) + CMSG_SPACE (sizeof (struct ucred))] = { 0 }; @@ -667,7 +670,6 @@ memif_msg_receive (int ifd) int err = MEMIF_ERR_SUCCESS; /* 0 */ int fd = -1; int i; - libmemif_main_t *lm = &libmemif_main; memif_connection_t *c = NULL; memif_socket_t *ms = NULL; memif_list_elt_t *elt = NULL; @@ -681,7 +683,6 @@ memif_msg_receive (int ifd) DBG ("recvmsg fd %d", ifd); size = recvmsg (ifd, &mh, 0); - DBG ("done"); if (size != sizeof (memif_msg_t)) { if (size == 0) @@ -809,8 +810,7 @@ memif_msg_receive (int ifd) if (c != NULL) c->flags |= MEMIF_CONNECTION_FLAG_WRITE; -/* libmemif_main_t *lm = &libmemif_main; - lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD); */ + return MEMIF_ERR_SUCCESS; /* 0 */ } @@ -827,8 +827,10 @@ memif_conn_fd_error (memif_connection_t * c) int memif_conn_fd_read_ready (memif_connection_t * c) { + libmemif_main_t *lm = get_libmemif_main (c->args.socket); int err; - err = memif_msg_receive (c->fd); + + err = memif_msg_receive (lm, c->fd); if (err != 0) { err = memif_disconnect_internal (c); @@ -840,7 +842,7 @@ memif_conn_fd_read_ready (memif_connection_t * c) int memif_conn_fd_write_ready (memif_connection_t * c) { - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (c->args.socket); int err = MEMIF_ERR_SUCCESS; /* 0 */ @@ -854,12 +856,7 @@ memif_conn_fd_write_ready (memif_connection_t * c) c->msg_queue = c->msg_queue->next; c->flags &= ~MEMIF_CONNECTION_FLAG_WRITE; -/* - libmemif_main_t *lm = &libmemif_main; - lm->control_fd_update (c->fd, - MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE | MEMIF_FD_EVENT_MOD); -*/ err = memif_msg_send (c->fd, &e->msg, e->fd); lm->free (e); goto done; @@ -874,7 +871,7 @@ memif_conn_fd_accept_ready (memif_socket_t * ms) int addr_len; struct sockaddr_un client; int conn_fd; - libmemif_main_t *lm = &libmemif_main; + libmemif_main_t *lm = get_libmemif_main (ms); DBG ("accept called"); @@ -893,18 +890,19 @@ memif_conn_fd_accept_ready (memif_socket_t * ms) elt.key = conn_fd; elt.data_struct = ms; - add_list_elt (&elt, &lm->pending_list, &lm->pending_list_len); - lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE); + add_list_elt (lm, &elt, &lm->pending_list, &lm->pending_list_len); + lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE, + lm->private_ctx); - return memif_msg_send_hello (conn_fd); + return memif_msg_send_hello (lm, conn_fd); } int -memif_read_ready (int fd) +memif_read_ready (libmemif_main_t * lm, int fd) { int err; - DBG ("call recv"); - err = memif_msg_receive (fd); - DBG ("recv finished"); + + err = memif_msg_receive (lm, fd); + return err; }