2 *------------------------------------------------------------------
3 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
19 #include <sys/socket.h>
20 #include <sys/types.h>
26 #include <sys/ioctl.h>
29 #include <sys/prctl.h>
36 /* sends msg to socket */
38 memif_msg_send (int fd, memif_msg_t * msg, int afd)
40 struct msghdr mh = { 0 };
42 char ctl[CMSG_SPACE (sizeof (int))];
43 int rv, err = MEMIF_ERR_SUCCESS; /* 0 */
45 iov[0].iov_base = (void *) msg;
46 iov[0].iov_len = sizeof (memif_msg_t);
53 memset (&ctl, 0, sizeof (ctl));
55 mh.msg_controllen = sizeof (ctl);
56 cmsg = CMSG_FIRSTHDR (&mh);
57 cmsg->cmsg_len = CMSG_LEN (sizeof (int));
58 cmsg->cmsg_level = SOL_SOCKET;
59 cmsg->cmsg_type = SCM_RIGHTS;
60 memcpy (CMSG_DATA (cmsg), &afd, sizeof (int));
62 rv = sendmsg (fd, &mh, 0);
64 err = memif_syscall_error_handler (errno);
65 DBG ("Message type %u sent", msg->type);
69 /* response from memif master - master is ready to handle next message */
71 memif_msg_enq_ack (memif_connection_t * c)
73 memif_msg_queue_elt_t *e =
74 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
76 return memif_syscall_error_handler (errno);
78 memset (&e->msg, 0, sizeof (e->msg));
79 e->msg.type = MEMIF_MSG_TYPE_ACK;
83 if (c->msg_queue == NULL)
86 return MEMIF_ERR_SUCCESS; /* 0 */
89 memif_msg_queue_elt_t *cur = c->msg_queue;
90 while (cur->next != NULL)
96 return MEMIF_ERR_SUCCESS; /* 0 */
100 memif_msg_send_hello (int fd)
102 libmemif_main_t *lm = &libmemif_main;
103 memif_msg_t msg = { 0 };
104 memif_msg_hello_t *h = &msg.hello;
105 msg.type = MEMIF_MSG_TYPE_HELLO;
106 h->min_version = MEMIF_VERSION;
107 h->max_version = MEMIF_VERSION;
108 h->max_s2m_ring = MEMIF_MAX_M2S_RING;
109 h->max_m2s_ring = MEMIF_MAX_M2S_RING;
110 h->max_region = MEMIF_MAX_REGION;
111 h->max_log2_ring_size = MEMIF_MAX_LOG2_RING_SIZE;
113 strncpy ((char *) h->name, lm->app_name, strlen (lm->app_name));
115 /* msg hello is not enqueued but sent directly,
116 because it is the first msg to be sent */
117 return memif_msg_send (fd, &msg, -1);
120 /* send id and secret (optional) for interface identification */
122 memif_msg_enq_init (memif_connection_t * c)
124 memif_msg_queue_elt_t *e =
125 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
127 return memif_syscall_error_handler (errno);
128 memset (e, 0, sizeof (memif_msg_queue_elt_t));
130 memset (&e->msg, 0, sizeof (e->msg));
131 memif_msg_init_t *i = &e->msg.init;
133 e->msg.type = MEMIF_MSG_TYPE_INIT;
135 i->version = MEMIF_VERSION;
136 i->id = c->args.interface_id;
137 i->mode = c->args.mode;
139 strncpy ((char *) i->name, (char *) c->args.instance_name,
140 strlen ((char *) c->args.instance_name));
142 strncpy ((char *) i->secret, (char *) c->args.secret, sizeof (i->secret));
145 if (c->msg_queue == NULL)
148 return MEMIF_ERR_SUCCESS; /* 0 */
151 memif_msg_queue_elt_t *cur = c->msg_queue;
152 while (cur->next != NULL)
158 return MEMIF_ERR_SUCCESS; /* 0 */
161 /* send information about region specified by region_index */
163 memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index)
165 /* maybe check if region is valid? */
166 memif_region_t *mr = &c->regions[region_index];
168 memif_msg_queue_elt_t *e =
169 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
171 return memif_syscall_error_handler (errno);
173 memset (&e->msg, 0, sizeof (e->msg));
174 memif_msg_add_region_t *ar = &e->msg.add_region;
176 e->msg.type = MEMIF_MSG_TYPE_ADD_REGION;
178 ar->index = region_index;
179 ar->size = mr->region_size;
182 if (c->msg_queue == NULL)
185 return MEMIF_ERR_SUCCESS; /* 0 */
188 memif_msg_queue_elt_t *cur = c->msg_queue;
189 while (cur->next != NULL)
195 return MEMIF_ERR_SUCCESS; /* 0 */
198 /* send information about ring specified by direction (S2M | M2S) and index */
200 memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir)
202 memif_msg_queue_elt_t *e =
203 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
205 return memif_syscall_error_handler (errno);
207 memset (&e->msg, 0, sizeof (e->msg));
208 memif_msg_add_ring_t *ar = &e->msg.add_ring;
210 e->msg.type = MEMIF_MSG_TYPE_ADD_RING;
212 /* TODO: support multiple rings */
214 if (dir == MEMIF_RING_M2S)
215 mq = &c->rx_queues[index];
217 mq = &c->tx_queues[index];
221 ar->offset = mq->offset;
222 ar->region = mq->region;
223 ar->log2_ring_size = mq->log2_ring_size;
224 ar->flags = (dir == MEMIF_RING_S2M) ? MEMIF_MSG_ADD_RING_FLAG_S2M : 0;
227 if (c->msg_queue == NULL)
230 return MEMIF_ERR_SUCCESS; /* 0 */
233 memif_msg_queue_elt_t *cur = c->msg_queue;
234 while (cur->next != NULL)
240 return MEMIF_ERR_SUCCESS; /* 0 */
243 /* used as connection request from slave */
245 memif_msg_enq_connect (memif_connection_t * c)
247 memif_msg_queue_elt_t *e =
248 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
250 return memif_syscall_error_handler (errno);
252 memset (&e->msg, 0, sizeof (e->msg));
253 memif_msg_connect_t *cm = &e->msg.connect;
255 e->msg.type = MEMIF_MSG_TYPE_CONNECT;
257 strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
258 strlen ((char *) c->args.interface_name));
261 if (c->msg_queue == NULL)
264 return MEMIF_ERR_SUCCESS; /* 0 */
267 memif_msg_queue_elt_t *cur = c->msg_queue;
268 while (cur->next != NULL)
274 return MEMIF_ERR_SUCCESS; /* 0 */
277 /* used as confirmation of connection by master */
279 memif_msg_enq_connected (memif_connection_t * c)
281 memif_msg_queue_elt_t *e =
282 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
284 return memif_syscall_error_handler (errno);
286 memset (&e->msg, 0, sizeof (e->msg));
287 memif_msg_connected_t *cm = &e->msg.connected;
289 e->msg.type = MEMIF_MSG_TYPE_CONNECTED;
291 strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
292 strlen ((char *) c->args.interface_name));
295 if (c->msg_queue == NULL)
298 return MEMIF_ERR_SUCCESS; /* 0 */
301 memif_msg_queue_elt_t *cur = c->msg_queue;
302 while (cur->next != NULL)
308 return MEMIF_ERR_SUCCESS; /* 0 */
311 /* immediately send disconnect msg */
312 /* specifie protocol for disconnect msg err_code
313 so that it will be compatible with VPP? (header/doc) */
315 memif_msg_send_disconnect (int fd, uint8_t * err_string, uint32_t err_code)
317 memif_msg_t msg = { 0 };
318 memif_msg_disconnect_t *d = &msg.disconnect;
320 msg.type = MEMIF_MSG_TYPE_DISCONNECT;
322 uint16_t l = strlen ((char *) err_string);
325 DBG ("Disconnect string too long. Sending first 96 characters.");
328 strncpy ((char *) d->string, (char *) err_string, l);
330 return memif_msg_send (fd, &msg, -1);
334 memif_msg_receive_hello (memif_connection_t * c, memif_msg_t * msg)
336 memif_msg_hello_t *h = &msg->hello;
338 if (msg->hello.min_version > MEMIF_VERSION ||
339 msg->hello.max_version < MEMIF_VERSION)
341 DBG ("incompatible protocol version");
342 return MEMIF_ERR_PROTO;
345 c->run_args.num_s2m_rings = memif_min (h->max_s2m_ring + 1,
346 c->args.num_s2m_rings);
347 c->run_args.num_m2s_rings = memif_min (h->max_m2s_ring + 1,
348 c->args.num_m2s_rings);
349 c->run_args.log2_ring_size = memif_min (h->max_log2_ring_size,
350 c->args.log2_ring_size);
351 c->run_args.buffer_size = c->args.buffer_size;
352 strncpy ((char *) c->remote_name, (char *) h->name,
353 strlen ((char *) h->name));
355 return MEMIF_ERR_SUCCESS; /* 0 */
358 /* handle interface identification (id, secret (optional)) */
360 memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
362 memif_msg_init_t *i = &msg->init;
363 memif_list_elt_t *elt = NULL;
364 memif_list_elt_t elt2;
365 memif_connection_t *c = NULL;
366 libmemif_main_t *lm = &libmemif_main;
367 uint8_t err_string[96];
368 memset (err_string, 0, sizeof (char) * 96);
369 int err = MEMIF_ERR_SUCCESS; /* 0 */
371 if (i->version != MEMIF_VERSION)
373 DBG ("MEMIF_VER_ERR");
374 strncpy ((char *) err_string, MEMIF_VER_ERR, strlen (MEMIF_VER_ERR));
375 err = MEMIF_ERR_PROTO;
379 get_list_elt (&elt, ms->interface_list, ms->interface_list_len, i->id);
382 DBG ("MEMIF_ID_ERR");
383 strncpy ((char *) err_string, MEMIF_ID_ERR, strlen (MEMIF_ID_ERR));
388 c = (memif_connection_t *) elt->data_struct;
390 if (!(c->args.is_master))
392 DBG ("MEMIF_SLAVE_ERR");
393 strncpy ((char *) err_string, MEMIF_SLAVE_ERR,
394 strlen (MEMIF_SLAVE_ERR));
395 err = MEMIF_ERR_ACCSLAVE;
400 DBG ("MEMIF_CONN_ERR");
401 strncpy ((char *) err_string, MEMIF_CONN_ERR, strlen (MEMIF_CONN_ERR));
402 err = MEMIF_ERR_ALRCONN;
408 if (i->mode != c->args.mode)
410 DBG ("MEMIF_MODE_ERR");
411 strncpy ((char *) err_string, MEMIF_MODE_ERR, strlen (MEMIF_MODE_ERR));
412 err = MEMIF_ERR_MODE;
416 strncpy ((char *) c->remote_name, (char *) i->name,
417 strlen ((char *) i->name));
424 if (strlen ((char *) c->args.secret) != strlen ((char *) i->secret))
426 DBG ("MEMIF_SECRET_ERR");
427 strncpy ((char *) err_string,
428 MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
429 err = MEMIF_ERR_SECRET;
432 r = strncmp ((char *) i->secret, (char *) c->args.secret,
433 strlen ((char *) c->args.secret));
436 DBG ("MEMIF_SECRET_ERR");
437 strncpy ((char *) err_string,
438 MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
439 err = MEMIF_ERR_SECRET;
445 DBG ("MEMIF_NOSECRET_ERR");
446 strncpy ((char *) err_string,
447 MEMIF_NOSECRET_ERR, strlen (MEMIF_NOSECRET_ERR));
448 err = MEMIF_ERR_NOSECRET;
453 c->read_fn = memif_conn_fd_read_ready;
454 c->write_fn = memif_conn_fd_write_ready;
455 c->error_fn = memif_conn_fd_error;
458 elt2.data_struct = c;
460 add_list_elt (&elt2, &lm->control_list, &lm->control_list_len);
461 free_list_elt (lm->pending_list, lm->pending_list_len, fd);
466 memif_msg_send_disconnect (fd, err_string, 0);
467 lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL);
468 free_list_elt (lm->pending_list, lm->pending_list_len, fd);
474 /* receive region information and add new region to connection (if possible) */
476 memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
479 memif_msg_add_region_t *ar = &msg->add_region;
482 return MEMIF_ERR_NO_SHMFD;
484 if (ar->index > MEMIF_MAX_REGION)
485 return MEMIF_ERR_MAXREG;
488 (memif_region_t *) realloc (c->regions,
489 sizeof (memif_region_t) * (ar->index + 1));
491 return memif_syscall_error_handler (errno);
493 c->regions[ar->index].fd = fd;
494 c->regions[ar->index].region_size = ar->size;
495 c->regions[ar->index].shm = NULL;
497 return MEMIF_ERR_SUCCESS; /* 0 */
500 /* receive ring information and add new ring to connection queue
501 (based on direction S2M | M2S) */
503 memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
505 memif_msg_add_ring_t *ar = &msg->add_ring;
510 return MEMIF_ERR_NO_INTFD;
512 if (ar->flags & MEMIF_MSG_ADD_RING_FLAG_S2M)
514 if (ar->index > MEMIF_MAX_S2M_RING)
515 return MEMIF_ERR_MAXRING;
516 if (ar->index >= c->args.num_s2m_rings)
517 return MEMIF_ERR_MAXRING;
520 (memif_queue_t *) realloc (c->rx_queues,
521 sizeof (memif_queue_t) * (ar->index + 1));
523 return memif_syscall_error_handler (errno);
525 c->rx_queues[ar->index].int_fd = fd;
526 c->rx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
527 c->rx_queues[ar->index].region = ar->region;
528 c->rx_queues[ar->index].offset = ar->offset;
529 c->run_args.num_s2m_rings++;
533 if (ar->index > MEMIF_MAX_M2S_RING)
534 return MEMIF_ERR_MAXRING;
535 if (ar->index >= c->args.num_m2s_rings)
536 return MEMIF_ERR_MAXRING;
539 (memif_queue_t *) realloc (c->tx_queues,
540 sizeof (memif_queue_t) * (ar->index + 1));
542 return memif_syscall_error_handler (errno);
544 c->tx_queues[ar->index].int_fd = fd;
545 c->tx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
546 c->tx_queues[ar->index].region = ar->region;
547 c->tx_queues[ar->index].offset = ar->offset;
548 c->run_args.num_m2s_rings++;
551 return MEMIF_ERR_SUCCESS; /* 0 */
554 /* slave -> master */
556 memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg)
558 memif_msg_connect_t *cm = &msg->connect;
559 libmemif_main_t *lm = &libmemif_main;
560 memif_list_elt_t elt;
563 err = memif_connect1 (c);
564 if (err != MEMIF_ERR_SUCCESS)
567 strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
568 strlen ((char *) cm->if_name));
571 if (c->on_interrupt != NULL)
573 for (i = 0; i < c->run_args.num_m2s_rings; i++)
575 elt.key = c->rx_queues[i].int_fd;
577 add_list_elt (&elt, &lm->interrupt_list, &lm->interrupt_list_len);
579 lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
584 c->on_connect ((void *) c, c->private_ctx);
589 /* master -> slave */
591 memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg)
593 memif_msg_connect_t *cm = &msg->connect;
594 libmemif_main_t *lm = &libmemif_main;
597 err = memif_connect1 (c);
598 if (err != MEMIF_ERR_SUCCESS)
601 strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
602 strlen ((char *) cm->if_name));
605 if (c->on_interrupt != NULL)
607 for (i = 0; i < c->run_args.num_s2m_rings; i++)
608 lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
611 c->on_connect ((void *) c, c->private_ctx);
617 memif_msg_receive_disconnect (memif_connection_t * c, memif_msg_t * msg)
619 memif_msg_disconnect_t *d = &msg->disconnect;
621 memset (c->remote_disconnect_string, 0,
622 sizeof (c->remote_disconnect_string));
623 strncpy ((char *) c->remote_disconnect_string, (char *) d->string,
624 strlen ((char *) d->string));
626 /* on returning error, handle function will call memif_disconnect () */
627 DBG ("disconnect received: %s, mode: %d",
628 c->remote_disconnect_string, c->args.mode);
629 return MEMIF_ERR_DISCONNECT;
633 memif_msg_receive (int ifd)
635 char ctl[CMSG_SPACE (sizeof (int)) +
636 CMSG_SPACE (sizeof (struct ucred))] = { 0 };
637 struct msghdr mh = { 0 };
639 memif_msg_t msg = { 0 };
641 int err = MEMIF_ERR_SUCCESS; /* 0 */
644 libmemif_main_t *lm = &libmemif_main;
645 memif_connection_t *c = NULL;
646 memif_socket_t *ms = NULL;
647 memif_list_elt_t *elt = NULL;
649 iov[0].iov_base = (void *) &msg;
650 iov[0].iov_len = sizeof (memif_msg_t);
653 mh.msg_control = ctl;
654 mh.msg_controllen = sizeof (ctl);
656 DBG ("recvmsg fd %d", ifd);
657 size = recvmsg (ifd, &mh, 0);
659 if (size != sizeof (memif_msg_t))
662 return MEMIF_ERR_DISCONNECTED;
664 return MEMIF_ERR_MFMSG;
667 struct ucred *cr = 0;
668 struct cmsghdr *cmsg;
670 cmsg = CMSG_FIRSTHDR (&mh);
673 if (cmsg->cmsg_level == SOL_SOCKET)
675 if (cmsg->cmsg_type == SCM_CREDENTIALS)
677 cr = (struct ucred *) CMSG_DATA (cmsg);
679 else if (cmsg->cmsg_type == SCM_RIGHTS)
681 int *fdp = (int *) CMSG_DATA (cmsg);
685 cmsg = CMSG_NXTHDR (&mh, cmsg);
688 DBG ("Message type %u received", msg.type);
690 get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
692 c = (memif_connection_t *) elt->data_struct;
696 case MEMIF_MSG_TYPE_ACK:
699 case MEMIF_MSG_TYPE_HELLO:
700 if ((err = memif_msg_receive_hello (c, &msg)) != MEMIF_ERR_SUCCESS)
702 if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
704 if ((err = memif_msg_enq_init (c)) != MEMIF_ERR_SUCCESS)
706 if ((err = memif_msg_enq_add_region (c, 0)) != MEMIF_ERR_SUCCESS)
708 for (i = 0; i < c->run_args.num_s2m_rings; i++)
711 memif_msg_enq_add_ring (c, i,
712 MEMIF_RING_S2M)) != MEMIF_ERR_SUCCESS)
715 for (i = 0; i < c->run_args.num_m2s_rings; i++)
718 memif_msg_enq_add_ring (c, i,
719 MEMIF_RING_M2S)) != MEMIF_ERR_SUCCESS)
722 if ((err = memif_msg_enq_connect (c)) != MEMIF_ERR_SUCCESS)
726 case MEMIF_MSG_TYPE_INIT:
727 get_list_elt (&elt, lm->pending_list, lm->pending_list_len, ifd);
730 ms = (memif_socket_t *) elt->data_struct;
731 if ((err = memif_msg_receive_init (ms, ifd, &msg)) != MEMIF_ERR_SUCCESS)
733 /* c->remote_pid = cr->pid */
734 /* c->remote_uid = cr->uid */
735 /* c->remote_gid = cr->gid */
736 get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
739 c = (memif_connection_t *) elt->data_struct;
740 if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
744 case MEMIF_MSG_TYPE_ADD_REGION:
746 memif_msg_receive_add_region (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
748 if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
752 case MEMIF_MSG_TYPE_ADD_RING:
754 memif_msg_receive_add_ring (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
756 if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
760 case MEMIF_MSG_TYPE_CONNECT:
761 if ((err = memif_msg_receive_connect (c, &msg)) != MEMIF_ERR_SUCCESS)
763 if ((err = memif_msg_enq_connected (c)) != MEMIF_ERR_SUCCESS)
767 case MEMIF_MSG_TYPE_CONNECTED:
768 if ((err = memif_msg_receive_connected (c, &msg)) != MEMIF_ERR_SUCCESS)
772 case MEMIF_MSG_TYPE_DISCONNECT:
773 if ((err = memif_msg_receive_disconnect (c, &msg)) != MEMIF_ERR_SUCCESS)
778 return MEMIF_ERR_UNKNOWN_MSG;;
783 c->flags |= MEMIF_CONNECTION_FLAG_WRITE;
784 /* libmemif_main_t *lm = &libmemif_main;
785 lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD); */
786 return MEMIF_ERR_SUCCESS; /* 0 */
790 memif_conn_fd_error (memif_connection_t * c)
792 DBG ("connection fd error");
793 strncpy ((char *) c->remote_disconnect_string, "connection fd error", 19);
794 int err = memif_disconnect_internal (c);
798 /* calls memif_msg_receive to handle pending messages on socket */
800 memif_conn_fd_read_ready (memif_connection_t * c)
803 err = memif_msg_receive (c->fd);
806 err = memif_disconnect_internal (c);
811 /* get msg from msg queue buffer and send it to socket */
813 memif_conn_fd_write_ready (memif_connection_t * c)
815 int err = MEMIF_ERR_SUCCESS; /* 0 */
818 if ((c->flags & MEMIF_CONNECTION_FLAG_WRITE) == 0)
821 memif_msg_queue_elt_t *e = c->msg_queue;
825 c->msg_queue = c->msg_queue->next;
827 c->flags &= ~MEMIF_CONNECTION_FLAG_WRITE;
829 libmemif_main_t *lm = &libmemif_main;
831 lm->control_fd_update (c->fd,
832 MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE | MEMIF_FD_EVENT_MOD);
834 err = memif_msg_send (c->fd, &e->msg, e->fd);
843 memif_conn_fd_accept_ready (memif_socket_t * ms)
846 struct sockaddr_un client;
848 libmemif_main_t *lm = &libmemif_main;
850 DBG ("accept called");
852 addr_len = sizeof (client);
854 accept (ms->fd, (struct sockaddr *) &client, (socklen_t *) & addr_len);
858 return memif_syscall_error_handler (errno);
860 DBG ("accept fd %d", ms->fd);
861 DBG ("conn fd %d", conn_fd);
863 memif_list_elt_t elt;
865 elt.data_struct = ms;
867 add_list_elt (&elt, &lm->pending_list, &lm->pending_list_len);
868 lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE);
870 return memif_msg_send_hello (conn_fd);
874 memif_read_ready (int fd)
878 err = memif_msg_receive (fd);
879 DBG ("recv finished");