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 #define memif_min(a,b) ((a < b) ? (a) : (b))
38 /* sends msg to socket */
40 memif_msg_send (int fd, memif_msg_t * msg, int afd)
42 struct msghdr mh = { 0 };
44 char ctl[CMSG_SPACE (sizeof (int))];
45 int rv, err = MEMIF_ERR_SUCCESS; /* 0 */
47 iov[0].iov_base = (void *) msg;
48 iov[0].iov_len = sizeof (memif_msg_t);
55 memset (&ctl, 0, sizeof (ctl));
57 mh.msg_controllen = sizeof (ctl);
58 cmsg = CMSG_FIRSTHDR (&mh);
59 cmsg->cmsg_len = CMSG_LEN (sizeof (int));
60 cmsg->cmsg_level = SOL_SOCKET;
61 cmsg->cmsg_type = SCM_RIGHTS;
62 memcpy (CMSG_DATA (cmsg), &afd, sizeof (int));
64 rv = sendmsg (fd, &mh, 0);
66 err = memif_syscall_error_handler (errno);
67 DBG ("Message type %u sent", msg->type);
71 /* response from memif master - master is ready to handle next message */
73 memif_msg_enq_ack (memif_connection_t * c)
75 memif_msg_queue_elt_t *e =
76 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
78 return memif_syscall_error_handler (errno);
80 memset (&e->msg, 0, sizeof (e->msg));
81 e->msg.type = MEMIF_MSG_TYPE_ACK;
85 if (c->msg_queue == NULL)
88 return MEMIF_ERR_SUCCESS; /* 0 */
91 memif_msg_queue_elt_t *cur = c->msg_queue;
92 while (cur->next != NULL)
98 return MEMIF_ERR_SUCCESS; /* 0 */
102 memif_msg_send_hello (int fd)
104 libmemif_main_t *lm = &libmemif_main;
105 memif_msg_t msg = { 0 };
106 memif_msg_hello_t *h = &msg.hello;
107 msg.type = MEMIF_MSG_TYPE_HELLO;
108 h->min_version = MEMIF_VERSION;
109 h->max_version = MEMIF_VERSION;
110 h->max_s2m_ring = MEMIF_MAX_M2S_RING;
111 h->max_m2s_ring = MEMIF_MAX_M2S_RING;
112 h->max_region = MEMIF_MAX_REGION;
113 h->max_log2_ring_size = MEMIF_MAX_LOG2_RING_SIZE;
115 strncpy ((char *) h->name, lm->app_name, strlen (lm->app_name));
117 /* msg hello is not enqueued but sent directly,
118 because it is the first msg to be sent */
119 return memif_msg_send (fd, &msg, -1);
122 /* send id and secret (optional) for interface identification */
124 memif_msg_enq_init (memif_connection_t * c)
126 memif_msg_queue_elt_t *e =
127 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
129 return memif_syscall_error_handler (errno);
130 memset (e, 0, sizeof (memif_msg_queue_elt_t));
132 memset (&e->msg, 0, sizeof (e->msg));
133 memif_msg_init_t *i = &e->msg.init;
135 e->msg.type = MEMIF_MSG_TYPE_INIT;
137 i->version = MEMIF_VERSION;
138 i->id = c->args.interface_id;
139 i->mode = c->args.mode;
141 strncpy ((char *) i->name, (char *) c->args.instance_name,
142 strlen ((char *) c->args.instance_name));
144 strncpy ((char *) i->secret, (char *) c->args.secret, sizeof (i->secret));
147 if (c->msg_queue == NULL)
150 return MEMIF_ERR_SUCCESS; /* 0 */
153 memif_msg_queue_elt_t *cur = c->msg_queue;
154 while (cur->next != NULL)
160 return MEMIF_ERR_SUCCESS; /* 0 */
163 /* send information about region specified by region_index */
165 memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index)
167 /* maybe check if region is valid? */
168 memif_region_t *mr = &c->regions[region_index];
170 memif_msg_queue_elt_t *e =
171 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
173 return memif_syscall_error_handler (errno);
175 memset (&e->msg, 0, sizeof (e->msg));
176 memif_msg_add_region_t *ar = &e->msg.add_region;
178 e->msg.type = MEMIF_MSG_TYPE_ADD_REGION;
180 ar->index = region_index;
181 ar->size = mr->region_size;
184 if (c->msg_queue == NULL)
187 return MEMIF_ERR_SUCCESS; /* 0 */
190 memif_msg_queue_elt_t *cur = c->msg_queue;
191 while (cur->next != NULL)
197 return MEMIF_ERR_SUCCESS; /* 0 */
200 /* send information about ring specified by direction (S2M | M2S) and index */
202 memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir)
204 memif_msg_queue_elt_t *e =
205 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
207 return memif_syscall_error_handler (errno);
209 memset (&e->msg, 0, sizeof (e->msg));
210 memif_msg_add_ring_t *ar = &e->msg.add_ring;
212 e->msg.type = MEMIF_MSG_TYPE_ADD_RING;
214 /* TODO: support multiple rings */
216 if (dir == MEMIF_RING_M2S)
217 mq = &c->rx_queues[index];
219 mq = &c->tx_queues[index];
223 ar->offset = mq->offset;
224 ar->region = mq->region;
225 ar->log2_ring_size = mq->log2_ring_size;
226 ar->flags = (dir == MEMIF_RING_S2M) ? MEMIF_MSG_ADD_RING_FLAG_S2M : 0;
229 if (c->msg_queue == NULL)
232 return MEMIF_ERR_SUCCESS; /* 0 */
235 memif_msg_queue_elt_t *cur = c->msg_queue;
236 while (cur->next != NULL)
242 return MEMIF_ERR_SUCCESS; /* 0 */
245 /* used as connection request from slave */
247 memif_msg_enq_connect (memif_connection_t * c)
249 memif_msg_queue_elt_t *e =
250 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
252 return memif_syscall_error_handler (errno);
254 memset (&e->msg, 0, sizeof (e->msg));
255 memif_msg_connect_t *cm = &e->msg.connect;
257 e->msg.type = MEMIF_MSG_TYPE_CONNECT;
259 strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
260 strlen ((char *) c->args.interface_name));
263 if (c->msg_queue == NULL)
266 return MEMIF_ERR_SUCCESS; /* 0 */
269 memif_msg_queue_elt_t *cur = c->msg_queue;
270 while (cur->next != NULL)
276 return MEMIF_ERR_SUCCESS; /* 0 */
279 /* used as confirmation of connection by master */
281 memif_msg_enq_connected (memif_connection_t * c)
283 memif_msg_queue_elt_t *e =
284 (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
286 return memif_syscall_error_handler (errno);
288 memset (&e->msg, 0, sizeof (e->msg));
289 memif_msg_connected_t *cm = &e->msg.connected;
291 e->msg.type = MEMIF_MSG_TYPE_CONNECTED;
293 strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
294 strlen ((char *) c->args.interface_name));
297 if (c->msg_queue == NULL)
300 return MEMIF_ERR_SUCCESS; /* 0 */
303 memif_msg_queue_elt_t *cur = c->msg_queue;
304 while (cur->next != NULL)
310 return MEMIF_ERR_SUCCESS; /* 0 */
313 /* immediately send disconnect msg */
314 /* specifie protocol for disconnect msg err_code
315 so that it will be compatible with VPP? (header/doc) */
317 memif_msg_send_disconnect (int fd, uint8_t * err_string, uint32_t err_code)
319 memif_msg_t msg = { 0 };
320 memif_msg_disconnect_t *d = &msg.disconnect;
322 msg.type = MEMIF_MSG_TYPE_DISCONNECT;
324 uint16_t l = strlen ((char *) err_string);
327 DBG ("Disconnect string too long. Sending first 96 characters.");
330 strncpy ((char *) d->string, (char *) err_string, l);
332 return memif_msg_send (fd, &msg, -1);
336 memif_msg_receive_hello (memif_connection_t * c, memif_msg_t * msg)
338 memif_msg_hello_t *h = &msg->hello;
340 if (msg->hello.min_version > MEMIF_VERSION ||
341 msg->hello.max_version < MEMIF_VERSION)
343 DBG ("incompatible protocol version");
344 return MEMIF_ERR_PROTO;
347 c->run_args.num_s2m_rings = memif_min (h->max_s2m_ring + 1,
348 c->args.num_s2m_rings);
349 c->run_args.num_m2s_rings = memif_min (h->max_m2s_ring + 1,
350 c->args.num_m2s_rings);
351 c->run_args.log2_ring_size = memif_min (h->max_log2_ring_size,
352 c->args.log2_ring_size);
353 c->run_args.buffer_size = c->args.buffer_size;
354 strncpy ((char *) c->remote_name, (char *) h->name,
355 strlen ((char *) h->name));
357 return MEMIF_ERR_SUCCESS; /* 0 */
360 /* handle interface identification (id, secret (optional)) */
362 memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
364 memif_msg_init_t *i = &msg->init;
365 memif_list_elt_t *elt = NULL;
366 memif_list_elt_t elt2;
367 memif_connection_t *c = NULL;
368 libmemif_main_t *lm = &libmemif_main;
369 uint8_t err_string[96];
370 memset (err_string, 0, sizeof (char) * 96);
371 int err = MEMIF_ERR_SUCCESS; /* 0 */
373 if (i->version != MEMIF_VERSION)
375 DBG ("MEMIF_VER_ERR");
376 strncpy ((char *) err_string, MEMIF_VER_ERR, strlen (MEMIF_VER_ERR));
377 err = MEMIF_ERR_PROTO;
381 get_list_elt (&elt, ms->interface_list, ms->interface_list_len, i->id);
384 DBG ("MEMIF_ID_ERR");
385 strncpy ((char *) err_string, MEMIF_ID_ERR, strlen (MEMIF_ID_ERR));
390 c = (memif_connection_t *) elt->data_struct;
392 if (!(c->args.is_master))
394 DBG ("MEMIF_SLAVE_ERR");
395 strncpy ((char *) err_string, MEMIF_SLAVE_ERR,
396 strlen (MEMIF_SLAVE_ERR));
397 err = MEMIF_ERR_ACCSLAVE;
402 DBG ("MEMIF_CONN_ERR");
403 strncpy ((char *) err_string, MEMIF_CONN_ERR, strlen (MEMIF_CONN_ERR));
404 err = MEMIF_ERR_ALRCONN;
410 if (i->mode != c->args.mode)
412 DBG ("MEMIF_MODE_ERR");
413 strncpy ((char *) err_string, MEMIF_MODE_ERR, strlen (MEMIF_MODE_ERR));
414 err = MEMIF_ERR_MODE;
418 strncpy ((char *) c->remote_name, (char *) i->name,
419 strlen ((char *) i->name));
426 if (strlen ((char *) c->args.secret) != strlen ((char *) i->secret))
428 DBG ("MEMIF_SECRET_ERR");
429 strncpy ((char *) err_string,
430 MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
431 err = MEMIF_ERR_SECRET;
434 r = strncmp ((char *) i->secret, (char *) c->args.secret,
435 strlen ((char *) c->args.secret));
438 DBG ("MEMIF_SECRET_ERR");
439 strncpy ((char *) err_string,
440 MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
441 err = MEMIF_ERR_SECRET;
447 DBG ("MEMIF_NOSECRET_ERR");
448 strncpy ((char *) err_string,
449 MEMIF_NOSECRET_ERR, strlen (MEMIF_NOSECRET_ERR));
450 err = MEMIF_ERR_NOSECRET;
455 c->read_fn = memif_conn_fd_read_ready;
456 c->write_fn = memif_conn_fd_write_ready;
457 c->error_fn = memif_conn_fd_error;
460 elt2.data_struct = c;
462 add_list_elt (&elt2, &lm->control_list, &lm->control_list_len);
463 free_list_elt (lm->pending_list, lm->pending_list_len, fd);
468 memif_msg_send_disconnect (fd, err_string, 0);
469 lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL);
470 free_list_elt (lm->pending_list, lm->pending_list_len, fd);
476 /* receive region information and add new region to connection (if possible) */
478 memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
481 memif_msg_add_region_t *ar = &msg->add_region;
484 return MEMIF_ERR_NO_SHMFD;
486 if (ar->index > MEMIF_MAX_REGION)
487 return MEMIF_ERR_MAXREG;
490 (memif_region_t *) realloc (c->regions,
491 sizeof (memif_region_t) * (ar->index + 1));
493 return memif_syscall_error_handler (errno);
495 c->regions[ar->index].fd = fd;
496 c->regions[ar->index].region_size = ar->size;
497 c->regions[ar->index].shm = NULL;
499 return MEMIF_ERR_SUCCESS; /* 0 */
502 /* receive ring information and add new ring to connection queue
503 (based on direction S2M | M2S) */
505 memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
507 memif_msg_add_ring_t *ar = &msg->add_ring;
512 return MEMIF_ERR_NO_INTFD;
514 if (ar->flags & MEMIF_MSG_ADD_RING_FLAG_S2M)
516 if (ar->index > MEMIF_MAX_S2M_RING)
517 return MEMIF_ERR_MAXRING;
518 if (ar->index >= c->args.num_s2m_rings)
519 return MEMIF_ERR_MAXRING;
522 (memif_queue_t *) realloc (c->rx_queues,
523 sizeof (memif_queue_t) * (ar->index + 1));
525 return memif_syscall_error_handler (errno);
527 c->rx_queues[ar->index].int_fd = fd;
528 c->rx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
529 c->rx_queues[ar->index].region = ar->region;
530 c->rx_queues[ar->index].offset = ar->offset;
531 c->run_args.num_s2m_rings++;
535 if (ar->index > MEMIF_MAX_M2S_RING)
536 return MEMIF_ERR_MAXRING;
537 if (ar->index >= c->args.num_m2s_rings)
538 return MEMIF_ERR_MAXRING;
541 (memif_queue_t *) realloc (c->tx_queues,
542 sizeof (memif_queue_t) * (ar->index + 1));
544 return memif_syscall_error_handler (errno);
546 c->tx_queues[ar->index].int_fd = fd;
547 c->tx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
548 c->tx_queues[ar->index].region = ar->region;
549 c->tx_queues[ar->index].offset = ar->offset;
550 c->run_args.num_m2s_rings++;
553 return MEMIF_ERR_SUCCESS; /* 0 */
556 /* slave -> master */
558 memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg)
560 memif_msg_connect_t *cm = &msg->connect;
561 libmemif_main_t *lm = &libmemif_main;
562 memif_list_elt_t elt;
565 err = memif_connect1 (c);
566 if (err != MEMIF_ERR_SUCCESS)
569 strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
570 strlen ((char *) cm->if_name));
573 if (c->on_interrupt != NULL)
575 for (i = 0; i < c->run_args.num_m2s_rings; i++)
577 elt.key = c->rx_queues[i].int_fd;
579 add_list_elt (&elt, &lm->interrupt_list, &lm->interrupt_list_len);
581 lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
586 c->on_connect ((void *) c, c->private_ctx);
591 /* master -> slave */
593 memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg)
595 memif_msg_connect_t *cm = &msg->connect;
596 libmemif_main_t *lm = &libmemif_main;
599 err = memif_connect1 (c);
600 if (err != MEMIF_ERR_SUCCESS)
603 strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
604 strlen ((char *) cm->if_name));
607 if (c->on_interrupt != NULL)
609 for (i = 0; i < c->run_args.num_s2m_rings; i++)
610 lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
613 c->on_connect ((void *) c, c->private_ctx);
619 memif_msg_receive_disconnect (memif_connection_t * c, memif_msg_t * msg)
621 memif_msg_disconnect_t *d = &msg->disconnect;
623 memset (c->remote_disconnect_string, 0,
624 sizeof (c->remote_disconnect_string));
625 strncpy ((char *) c->remote_disconnect_string, (char *) d->string,
626 strlen ((char *) d->string));
628 /* on returning error, handle function will call memif_disconnect () */
629 DBG ("disconnect received: %s, mode: %d",
630 c->remote_disconnect_string, c->args.mode);
631 return MEMIF_ERR_DISCONNECT;
635 memif_msg_receive (int ifd)
637 char ctl[CMSG_SPACE (sizeof (int)) +
638 CMSG_SPACE (sizeof (struct ucred))] = { 0 };
639 struct msghdr mh = { 0 };
641 memif_msg_t msg = { 0 };
643 int err = MEMIF_ERR_SUCCESS; /* 0 */
646 libmemif_main_t *lm = &libmemif_main;
647 memif_connection_t *c = NULL;
648 memif_socket_t *ms = NULL;
649 memif_list_elt_t *elt = NULL;
651 iov[0].iov_base = (void *) &msg;
652 iov[0].iov_len = sizeof (memif_msg_t);
655 mh.msg_control = ctl;
656 mh.msg_controllen = sizeof (ctl);
658 DBG ("recvmsg fd %d", ifd);
659 size = recvmsg (ifd, &mh, 0);
661 if (size != sizeof (memif_msg_t))
664 return MEMIF_ERR_DISCONNECTED;
666 return MEMIF_ERR_MFMSG;
669 struct ucred *cr = 0;
670 struct cmsghdr *cmsg;
672 cmsg = CMSG_FIRSTHDR (&mh);
675 if (cmsg->cmsg_level == SOL_SOCKET)
677 if (cmsg->cmsg_type == SCM_CREDENTIALS)
679 cr = (struct ucred *) CMSG_DATA (cmsg);
681 else if (cmsg->cmsg_type == SCM_RIGHTS)
683 int *fdp = (int *) CMSG_DATA (cmsg);
687 cmsg = CMSG_NXTHDR (&mh, cmsg);
690 DBG ("Message type %u received", msg.type);
692 get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
694 c = (memif_connection_t *) elt->data_struct;
698 case MEMIF_MSG_TYPE_ACK:
701 case MEMIF_MSG_TYPE_HELLO:
702 if ((err = memif_msg_receive_hello (c, &msg)) != MEMIF_ERR_SUCCESS)
704 if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
706 if ((err = memif_msg_enq_init (c)) != MEMIF_ERR_SUCCESS)
708 if ((err = memif_msg_enq_add_region (c, 0)) != MEMIF_ERR_SUCCESS)
710 for (i = 0; i < c->run_args.num_s2m_rings; i++)
713 memif_msg_enq_add_ring (c, i,
714 MEMIF_RING_S2M)) != MEMIF_ERR_SUCCESS)
717 for (i = 0; i < c->run_args.num_m2s_rings; i++)
720 memif_msg_enq_add_ring (c, i,
721 MEMIF_RING_M2S)) != MEMIF_ERR_SUCCESS)
724 if ((err = memif_msg_enq_connect (c)) != MEMIF_ERR_SUCCESS)
728 case MEMIF_MSG_TYPE_INIT:
729 get_list_elt (&elt, lm->pending_list, lm->pending_list_len, ifd);
732 ms = (memif_socket_t *) elt->data_struct;
733 if ((err = memif_msg_receive_init (ms, ifd, &msg)) != MEMIF_ERR_SUCCESS)
735 /* c->remote_pid = cr->pid */
736 /* c->remote_uid = cr->uid */
737 /* c->remote_gid = cr->gid */
738 get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
741 c = (memif_connection_t *) elt->data_struct;
742 if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
746 case MEMIF_MSG_TYPE_ADD_REGION:
748 memif_msg_receive_add_region (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
750 if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
754 case MEMIF_MSG_TYPE_ADD_RING:
756 memif_msg_receive_add_ring (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
758 if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
762 case MEMIF_MSG_TYPE_CONNECT:
763 if ((err = memif_msg_receive_connect (c, &msg)) != MEMIF_ERR_SUCCESS)
765 if ((err = memif_msg_enq_connected (c)) != MEMIF_ERR_SUCCESS)
769 case MEMIF_MSG_TYPE_CONNECTED:
770 if ((err = memif_msg_receive_connected (c, &msg)) != MEMIF_ERR_SUCCESS)
774 case MEMIF_MSG_TYPE_DISCONNECT:
775 if ((err = memif_msg_receive_disconnect (c, &msg)) != MEMIF_ERR_SUCCESS)
780 return MEMIF_ERR_UNKNOWN_MSG;;
785 c->flags |= MEMIF_CONNECTION_FLAG_WRITE;
786 /* libmemif_main_t *lm = &libmemif_main;
787 lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD); */
788 return MEMIF_ERR_SUCCESS; /* 0 */
792 memif_conn_fd_error (memif_connection_t * c)
794 DBG ("connection fd error");
795 strncpy ((char *) c->remote_disconnect_string, "connection fd error", 19);
796 int err = memif_disconnect_internal (c);
800 /* calls memif_msg_receive to handle pending messages on socket */
802 memif_conn_fd_read_ready (memif_connection_t * c)
805 err = memif_msg_receive (c->fd);
808 err = memif_disconnect_internal (c);
813 /* get msg from msg queue buffer and send it to socket */
815 memif_conn_fd_write_ready (memif_connection_t * c)
817 int err = MEMIF_ERR_SUCCESS; /* 0 */
820 if ((c->flags & MEMIF_CONNECTION_FLAG_WRITE) == 0)
823 memif_msg_queue_elt_t *e = c->msg_queue;
827 c->msg_queue = c->msg_queue->next;
829 c->flags &= ~MEMIF_CONNECTION_FLAG_WRITE;
831 libmemif_main_t *lm = &libmemif_main;
833 lm->control_fd_update (c->fd,
834 MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE | MEMIF_FD_EVENT_MOD);
836 err = memif_msg_send (c->fd, &e->msg, e->fd);
845 memif_conn_fd_accept_ready (memif_socket_t * ms)
848 struct sockaddr_un client;
850 libmemif_main_t *lm = &libmemif_main;
852 DBG ("accept called");
854 addr_len = sizeof (client);
856 accept (ms->fd, (struct sockaddr *) &client, (socklen_t *) & addr_len);
860 return memif_syscall_error_handler (errno);
862 DBG ("accept fd %d", ms->fd);
863 DBG ("conn fd %d", conn_fd);
865 memif_list_elt_t elt;
867 elt.data_struct = ms;
869 add_list_elt (&elt, &lm->pending_list, &lm->pending_list_len);
870 lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE);
872 return memif_msg_send_hello (conn_fd);
876 memif_read_ready (int fd)
880 err = memif_msg_receive (fd);
881 DBG ("recv finished");