2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011-2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; only
8 * version 2.1 of the License.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <sys/socket.h>
27 #include <sys/types.h>
34 #include <lttng/ust-ctl.h>
37 #include <lttng/ust-error.h>
38 #include <lttng/ust-events.h>
39 #include <usterr-signal-safe.h>
41 #include "../liblttng-ust/compat.h"
43 #define USTCOMM_CODE_OFFSET(code) \
44 (code == LTTNG_UST_OK ? 0 : (code - LTTNG_UST_ERR + 1))
46 #define USTCOMM_MAX_SEND_FDS 4
49 * Human readable error message.
51 static const char *ustcomm_readable_code
[] = {
52 [ USTCOMM_CODE_OFFSET(LTTNG_UST_OK
) ] = "Success",
53 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR
) ] = "Unknown error",
54 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_NOENT
) ] = "No entry",
55 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_EXIST
) ] = "Object already exists",
56 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL
) ] = "Invalid argument",
57 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PERM
) ] = "Permission denied",
58 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_NOSYS
) ] = "Not implemented",
59 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_EXITING
) ] = "Process is exiting",
61 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_MAGIC
) ] = "Invalid magic number",
62 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_SOCKET_TYPE
) ] = "Invalid socket type",
63 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_UNSUP_MAJOR
) ] = "Unsupported major version",
69 * Receives positive error value.
70 * Return ptr to string representing a human readable
71 * error code from the ustcomm_return_code enum.
73 const char *lttng_ust_strerror(int code
)
75 if (code
== LTTNG_UST_OK
)
76 return ustcomm_readable_code
[USTCOMM_CODE_OFFSET(code
)];
77 if (code
< LTTNG_UST_ERR
)
78 return strerror(code
);
79 if (code
>= LTTNG_UST_ERR_NR
)
81 return ustcomm_readable_code
[USTCOMM_CODE_OFFSET(code
)];
86 * ustcomm_connect_unix_sock
88 * Connect to unix socket using the path name.
90 int ustcomm_connect_unix_sock(const char *pathname
)
92 struct sockaddr_un sun
;
96 * libust threads require the close-on-exec flag for all
97 * resources so it does not leak file descriptors upon exec.
99 fd
= socket(PF_UNIX
, SOCK_STREAM
, 0);
105 ret
= fcntl(fd
, F_SETFD
, FD_CLOEXEC
);
112 memset(&sun
, 0, sizeof(sun
));
113 sun
.sun_family
= AF_UNIX
;
114 strncpy(sun
.sun_path
, pathname
, sizeof(sun
.sun_path
));
115 sun
.sun_path
[sizeof(sun
.sun_path
) - 1] = '\0';
117 ret
= connect(fd
, (struct sockaddr
*) &sun
, sizeof(sun
));
120 * Don't print message on connect error, because connect
121 * is used in normal execution to detect if sessiond is
135 closeret
= close(fd
);
144 * ustcomm_accept_unix_sock
146 * Do an accept(2) on the sock and return the
147 * new file descriptor. The socket MUST be bind(2) before.
149 int ustcomm_accept_unix_sock(int sock
)
152 struct sockaddr_un sun
;
156 new_fd
= accept(sock
, (struct sockaddr
*) &sun
, &len
);
165 * ustcomm_create_unix_sock
167 * Creates a AF_UNIX local socket using pathname
168 * bind the socket upon creation and return the fd.
170 int ustcomm_create_unix_sock(const char *pathname
)
172 struct sockaddr_un sun
;
175 /* Create server socket */
176 if ((fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) < 0) {
182 memset(&sun
, 0, sizeof(sun
));
183 sun
.sun_family
= AF_UNIX
;
184 strncpy(sun
.sun_path
, pathname
, sizeof(sun
.sun_path
));
185 sun
.sun_path
[sizeof(sun
.sun_path
) - 1] = '\0';
187 /* Unlink the old file if present */
188 (void) unlink(pathname
);
189 ret
= bind(fd
, (struct sockaddr
*) &sun
, sizeof(sun
));
202 closeret
= close(fd
);
212 * ustcomm_listen_unix_sock
214 * Make the socket listen using LTTNG_UST_COMM_MAX_LISTEN.
216 int ustcomm_listen_unix_sock(int sock
)
220 ret
= listen(sock
, LTTNG_UST_COMM_MAX_LISTEN
);
230 * ustcomm_close_unix_sock
232 * Shutdown cleanly a unix socket.
234 int ustcomm_close_unix_sock(int sock
)
248 * ustcomm_recv_unix_sock
250 * Receive data of size len in put that data into
251 * the buf param. Using recvmsg API.
252 * Return the size of received data.
253 * Return 0 on orderly shutdown.
255 ssize_t
ustcomm_recv_unix_sock(int sock
, void *buf
, size_t len
)
261 memset(&msg
, 0, sizeof(msg
));
263 iov
[0].iov_base
= buf
;
264 iov
[0].iov_len
= len
;
269 ret
= recvmsg(sock
, &msg
, 0);
270 } while (ret
< 0 && errno
== EINTR
);
275 if (errno
!= EPIPE
&& errno
!= ECONNRESET
)
279 shutret
= shutdown(sock
, SHUT_RDWR
);
281 ERR("Socket shutdown error");
288 * ustcomm_send_unix_sock
290 * Send buf data of size len. Using sendmsg API.
291 * Return the size of sent data.
293 ssize_t
ustcomm_send_unix_sock(int sock
, const void *buf
, size_t len
)
299 memset(&msg
, 0, sizeof(msg
));
301 iov
[0].iov_base
= (void *) buf
;
302 iov
[0].iov_len
= len
;
307 * Using the MSG_NOSIGNAL when sending data from sessiond to
308 * libust, so libust does not receive an unhandled SIGPIPE or
309 * SIGURG. The sessiond receiver side can be made more resilient
310 * by ignoring SIGPIPE, but we don't have this luxury on the
314 ret
= sendmsg(sock
, &msg
, MSG_NOSIGNAL
);
315 } while (ret
< 0 && errno
== EINTR
);
320 if (errno
!= EPIPE
&& errno
!= ECONNRESET
)
324 shutret
= shutdown(sock
, SHUT_RDWR
);
326 ERR("Socket shutdown error");
333 * Send a message accompanied by fd(s) over a unix socket.
335 * Returns the size of data sent, or negative error value.
337 ssize_t
ustcomm_send_fds_unix_sock(int sock
, int *fds
, size_t nb_fd
)
340 struct cmsghdr
*cmptr
;
343 unsigned int sizeof_fds
= nb_fd
* sizeof(int);
344 char tmp
[CMSG_SPACE(sizeof_fds
)];
347 memset(&msg
, 0, sizeof(msg
));
348 memset(tmp
, 0, CMSG_SPACE(sizeof_fds
) * sizeof(char));
350 if (nb_fd
> USTCOMM_MAX_SEND_FDS
)
353 msg
.msg_control
= (caddr_t
)tmp
;
354 msg
.msg_controllen
= CMSG_LEN(sizeof_fds
);
356 cmptr
= CMSG_FIRSTHDR(&msg
);
357 cmptr
->cmsg_level
= SOL_SOCKET
;
358 cmptr
->cmsg_type
= SCM_RIGHTS
;
359 cmptr
->cmsg_len
= CMSG_LEN(sizeof_fds
);
360 memcpy(CMSG_DATA(cmptr
), fds
, sizeof_fds
);
361 /* Sum of the length of all control messages in the buffer: */
362 msg
.msg_controllen
= cmptr
->cmsg_len
;
364 iov
[0].iov_base
= &dummy
;
370 ret
= sendmsg(sock
, &msg
, 0);
371 } while (ret
< 0 && errno
== EINTR
);
374 * We consider EPIPE and ECONNRESET as expected.
376 if (errno
!= EPIPE
&& errno
!= ECONNRESET
) {
384 * Recv a message accompanied by fd(s) from a unix socket.
386 * Returns the size of received data, or negative error value.
388 * Expect at most "nb_fd" file descriptors. Returns the number of fd
389 * actually received in nb_fd.
390 * Returns -EPIPE on orderly shutdown.
392 ssize_t
ustcomm_recv_fds_unix_sock(int sock
, int *fds
, size_t nb_fd
)
396 struct cmsghdr
*cmsg
;
397 size_t sizeof_fds
= nb_fd
* sizeof(int);
398 char recv_fd
[CMSG_SPACE(sizeof_fds
)];
402 memset(&msg
, 0, sizeof(msg
));
404 /* Prepare to receive the structures */
405 iov
[0].iov_base
= &dummy
;
409 msg
.msg_control
= recv_fd
;
410 msg
.msg_controllen
= sizeof(recv_fd
);
413 ret
= recvmsg(sock
, &msg
, 0);
414 } while (ret
< 0 && errno
== EINTR
);
416 if (errno
!= EPIPE
&& errno
!= ECONNRESET
) {
417 PERROR("recvmsg fds");
419 if (errno
== EPIPE
|| errno
== ECONNRESET
)
424 /* orderly shutdown */
429 ERR("Error: Received %zd bytes, expected %d\n",
433 if (msg
.msg_flags
& MSG_CTRUNC
) {
434 ERR("Error: Control message truncated.\n");
438 cmsg
= CMSG_FIRSTHDR(&msg
);
440 ERR("Error: Invalid control message header\n");
444 if (cmsg
->cmsg_level
!= SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
445 ERR("Didn't received any fd\n");
449 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof_fds
)) {
450 ERR("Error: Received %zu bytes of ancillary data, expected %zu\n",
451 (size_t) cmsg
->cmsg_len
, (size_t) CMSG_LEN(sizeof_fds
));
455 memcpy(fds
, CMSG_DATA(cmsg
), sizeof_fds
);
461 int ustcomm_send_app_msg(int sock
, struct ustcomm_ust_msg
*lum
)
465 len
= ustcomm_send_unix_sock(sock
, lum
, sizeof(*lum
));
473 ERR("incorrect message size: %zd\n", len
);
480 int ustcomm_recv_app_reply(int sock
, struct ustcomm_ust_reply
*lur
,
481 uint32_t expected_handle
, uint32_t expected_cmd
)
485 memset(lur
, 0, sizeof(*lur
));
486 len
= ustcomm_recv_unix_sock(sock
, lur
, sizeof(*lur
));
488 case 0: /* orderly shutdown */
491 if (lur
->handle
!= expected_handle
) {
492 ERR("Unexpected result message handle: "
493 "expected: %u vs received: %u\n",
494 expected_handle
, lur
->handle
);
497 if (lur
->cmd
!= expected_cmd
) {
498 ERR("Unexpected result message command "
499 "expected: %u vs received: %u\n",
500 expected_cmd
, lur
->cmd
);
503 return lur
->ret_code
;
506 /* Transport level error */
507 if (errno
== EPIPE
|| errno
== ECONNRESET
)
511 ERR("incorrect message size: %zd\n", len
);
517 int ustcomm_send_app_cmd(int sock
,
518 struct ustcomm_ust_msg
*lum
,
519 struct ustcomm_ust_reply
*lur
)
523 ret
= ustcomm_send_app_msg(sock
, lum
);
526 ret
= ustcomm_recv_app_reply(sock
, lur
, lum
->handle
, lum
->cmd
);
533 * chan_data is allocated internally if this function returns the
536 ssize_t
ustcomm_recv_channel_from_sessiond(int sock
,
537 void **_chan_data
, uint64_t var_len
)
542 if (var_len
> LTTNG_UST_CHANNEL_DATA_MAX_LEN
) {
546 /* Receive variable length data */
547 chan_data
= zmalloc(var_len
);
552 len
= ustcomm_recv_unix_sock(sock
, chan_data
, var_len
);
553 if (len
!= var_len
) {
556 *_chan_data
= chan_data
;
566 int ustcomm_recv_stream_from_sessiond(int sock
,
567 uint64_t *memory_map_size
,
568 int *shm_fd
, int *wakeup_fd
)
574 /* recv shm fd and wakeup fd */
575 len
= ustcomm_recv_fds_unix_sock(sock
, fds
, 2);
594 * Returns 0 on success, negative error value on error.
596 int ustcomm_send_reg_msg(int sock
,
597 enum ustctl_socket_type type
,
598 uint32_t bits_per_long
,
599 uint32_t uint8_t_alignment
,
600 uint32_t uint16_t_alignment
,
601 uint32_t uint32_t_alignment
,
602 uint32_t uint64_t_alignment
,
603 uint32_t long_alignment
)
606 struct ustctl_reg_msg reg_msg
;
608 reg_msg
.magic
= LTTNG_UST_COMM_MAGIC
;
609 reg_msg
.major
= LTTNG_UST_ABI_MAJOR_VERSION
;
610 reg_msg
.minor
= LTTNG_UST_ABI_MINOR_VERSION
;
611 reg_msg
.pid
= getpid();
612 reg_msg
.ppid
= getppid();
613 reg_msg
.uid
= getuid();
614 reg_msg
.gid
= getgid();
615 reg_msg
.bits_per_long
= bits_per_long
;
616 reg_msg
.uint8_t_alignment
= uint8_t_alignment
;
617 reg_msg
.uint16_t_alignment
= uint16_t_alignment
;
618 reg_msg
.uint32_t_alignment
= uint32_t_alignment
;
619 reg_msg
.uint64_t_alignment
= uint64_t_alignment
;
620 reg_msg
.long_alignment
= long_alignment
;
621 reg_msg
.socket_type
= type
;
622 lttng_ust_getprocname(reg_msg
.name
);
623 memset(reg_msg
.padding
, 0, sizeof(reg_msg
.padding
));
625 len
= ustcomm_send_unix_sock(sock
, ®_msg
, sizeof(reg_msg
));
626 if (len
> 0 && len
!= sizeof(reg_msg
))
634 int serialize_basic_type(enum ustctl_abstract_types
*uatype
,
635 enum lttng_abstract_types atype
,
636 union _ustctl_basic_type
*ubt
,
637 const union _lttng_basic_type
*lbt
)
642 struct ustctl_integer_type
*uit
;
643 const struct lttng_integer_type
*lit
;
647 uit
->size
= lit
->size
;
648 uit
->signedness
= lit
->signedness
;
649 uit
->reverse_byte_order
= lit
->reverse_byte_order
;
650 uit
->base
= lit
->base
;
651 uit
->encoding
= lit
->encoding
;
652 uit
->alignment
= lit
->alignment
;
653 *uatype
= ustctl_atype_integer
;
658 ubt
->string
.encoding
= lbt
->string
.encoding
;
659 *uatype
= ustctl_atype_string
;
664 struct ustctl_float_type
*uft
;
665 const struct lttng_float_type
*lft
;
669 uft
->exp_dig
= lft
->exp_dig
;
670 uft
->mant_dig
= lft
->mant_dig
;
671 uft
->alignment
= lft
->alignment
;
672 uft
->reverse_byte_order
= lft
->reverse_byte_order
;
673 *uatype
= ustctl_atype_float
;
686 int serialize_one_type(struct ustctl_type
*ut
, const struct lttng_type
*lt
)
694 ret
= serialize_basic_type(&ut
->atype
, lt
->atype
,
695 &ut
->u
.basic
, <
->u
.basic
);
701 struct ustctl_basic_type
*ubt
;
702 const struct lttng_basic_type
*lbt
;
705 ubt
= &ut
->u
.array
.elem_type
;
706 lbt
= <
->u
.array
.elem_type
;
707 ut
->u
.array
.length
= lt
->u
.array
.length
;
708 ret
= serialize_basic_type(&ubt
->atype
, lbt
->atype
,
709 &ubt
->u
.basic
, &lbt
->u
.basic
);
712 ut
->atype
= ustctl_atype_array
;
717 struct ustctl_basic_type
*ubt
;
718 const struct lttng_basic_type
*lbt
;
721 ubt
= &ut
->u
.sequence
.length_type
;
722 lbt
= <
->u
.sequence
.length_type
;
723 ret
= serialize_basic_type(&ubt
->atype
, lbt
->atype
,
724 &ubt
->u
.basic
, &lbt
->u
.basic
);
727 ubt
= &ut
->u
.sequence
.elem_type
;
728 lbt
= <
->u
.sequence
.elem_type
;
729 ret
= serialize_basic_type(&ubt
->atype
, lbt
->atype
,
730 &ubt
->u
.basic
, &lbt
->u
.basic
);
733 ut
->atype
= ustctl_atype_sequence
;
744 int serialize_fields(size_t *_nr_write_fields
,
745 struct ustctl_field
**ustctl_fields
,
747 const struct lttng_event_field
*lttng_fields
)
749 struct ustctl_field
*fields
;
751 size_t nr_write_fields
= 0;
753 fields
= zmalloc(nr_fields
* sizeof(*fields
));
757 for (i
= 0; i
< nr_fields
; i
++) {
758 struct ustctl_field
*f
;
759 const struct lttng_event_field
*lf
;
761 f
= &fields
[nr_write_fields
];
762 lf
= <tng_fields
[i
];
764 /* skip 'nowrite' fields */
767 strncpy(f
->name
, lf
->name
, LTTNG_UST_SYM_NAME_LEN
);
768 f
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
769 ret
= serialize_one_type(&f
->type
, &lf
->type
);
775 *_nr_write_fields
= nr_write_fields
;
776 *ustctl_fields
= fields
;
785 * Returns 0 on success, negative error value on error.
787 int ustcomm_register_event(int sock
,
788 int session_objd
, /* session descriptor */
789 int channel_objd
, /* channel descriptor */
790 const char *event_name
, /* event name (input) */
792 const char *signature
, /* event signature (input) */
793 size_t nr_fields
, /* fields */
794 const struct lttng_event_field
*lttng_fields
,
795 const char *model_emf_uri
,
796 uint32_t *id
) /* event id (output) */
800 struct ustcomm_notify_hdr header
;
801 struct ustcomm_notify_event_msg m
;
804 struct ustcomm_notify_hdr header
;
805 struct ustcomm_notify_event_reply r
;
807 size_t signature_len
, fields_len
, model_emf_uri_len
;
808 struct ustctl_field
*fields
;
809 size_t nr_write_fields
= 0;
812 memset(&msg
, 0, sizeof(msg
));
813 msg
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
814 msg
.m
.session_objd
= session_objd
;
815 msg
.m
.channel_objd
= channel_objd
;
816 strncpy(msg
.m
.event_name
, event_name
, LTTNG_UST_SYM_NAME_LEN
);
817 msg
.m
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
818 msg
.m
.loglevel
= loglevel
;
819 signature_len
= strlen(signature
) + 1;
820 msg
.m
.signature_len
= signature_len
;
822 /* Calculate fields len, serialize fields. */
824 ret
= serialize_fields(&nr_write_fields
, &fields
,
825 nr_fields
, lttng_fields
);
830 fields_len
= sizeof(*fields
) * nr_write_fields
;
831 msg
.m
.fields_len
= fields_len
;
833 model_emf_uri_len
= strlen(model_emf_uri
) + 1;
835 model_emf_uri_len
= 0;
837 msg
.m
.model_emf_uri_len
= model_emf_uri_len
;
838 len
= ustcomm_send_unix_sock(sock
, &msg
, sizeof(msg
));
839 if (len
> 0 && len
!= sizeof(msg
)) {
849 len
= ustcomm_send_unix_sock(sock
, signature
, signature_len
);
850 if (len
> 0 && len
!= signature_len
) {
860 if (fields_len
> 0) {
861 len
= ustcomm_send_unix_sock(sock
, fields
, fields_len
);
863 if (len
> 0 && len
!= fields_len
) {
871 if (model_emf_uri_len
) {
872 /* send model_emf_uri */
873 len
= ustcomm_send_unix_sock(sock
, model_emf_uri
,
875 if (len
> 0 && len
!= model_emf_uri_len
)
882 len
= ustcomm_recv_unix_sock(sock
, &reply
, sizeof(reply
));
884 case 0: /* orderly shutdown */
887 if (reply
.header
.notify_cmd
!= msg
.header
.notify_cmd
) {
888 ERR("Unexpected result message command "
889 "expected: %u vs received: %u\n",
890 msg
.header
.notify_cmd
, reply
.header
.notify_cmd
);
893 if (reply
.r
.ret_code
> 0)
895 if (reply
.r
.ret_code
< 0)
896 return reply
.r
.ret_code
;
897 *id
= reply
.r
.event_id
;
898 DBG("Sent register event notification for name \"%s\": ret_code %d, event_id %u\n",
899 event_name
, reply
.r
.ret_code
, reply
.r
.event_id
);
903 /* Transport level error */
904 if (errno
== EPIPE
|| errno
== ECONNRESET
)
908 ERR("incorrect message size: %zd\n", len
);
915 * Returns 0 on success, negative error value on error.
916 * Returns -EPIPE or -ECONNRESET if other end has hung up.
918 int ustcomm_register_channel(int sock
,
919 int session_objd
, /* session descriptor */
920 int channel_objd
, /* channel descriptor */
921 size_t nr_ctx_fields
,
922 const struct lttng_event_field
*ctx_fields
,
923 uint32_t *chan_id
, /* channel id (output) */
924 int *header_type
) /* header type (output) */
928 struct ustcomm_notify_hdr header
;
929 struct ustcomm_notify_channel_msg m
;
932 struct ustcomm_notify_hdr header
;
933 struct ustcomm_notify_channel_reply r
;
936 struct ustctl_field
*fields
;
938 size_t nr_write_fields
= 0;
940 memset(&msg
, 0, sizeof(msg
));
941 msg
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
942 msg
.m
.session_objd
= session_objd
;
943 msg
.m
.channel_objd
= channel_objd
;
945 /* Calculate fields len, serialize fields. */
946 if (nr_ctx_fields
> 0) {
947 ret
= serialize_fields(&nr_write_fields
, &fields
,
948 nr_ctx_fields
, ctx_fields
);
953 fields_len
= sizeof(*fields
) * nr_write_fields
;
954 msg
.m
.ctx_fields_len
= fields_len
;
955 len
= ustcomm_send_unix_sock(sock
, &msg
, sizeof(msg
));
956 if (len
> 0 && len
!= sizeof(msg
)) {
966 if (fields_len
> 0) {
967 len
= ustcomm_send_unix_sock(sock
, fields
, fields_len
);
969 if (len
> 0 && len
!= fields_len
) {
977 len
= ustcomm_recv_unix_sock(sock
, &reply
, sizeof(reply
));
979 case 0: /* orderly shutdown */
982 if (reply
.header
.notify_cmd
!= msg
.header
.notify_cmd
) {
983 ERR("Unexpected result message command "
984 "expected: %u vs received: %u\n",
985 msg
.header
.notify_cmd
, reply
.header
.notify_cmd
);
988 if (reply
.r
.ret_code
> 0)
990 if (reply
.r
.ret_code
< 0)
991 return reply
.r
.ret_code
;
992 *chan_id
= reply
.r
.chan_id
;
993 switch (reply
.r
.header_type
) {
996 *header_type
= reply
.r
.header_type
;
999 ERR("Unexpected channel header type %u\n",
1000 reply
.r
.header_type
);
1003 DBG("Sent register channel notification: chan_id %d, header_type %d\n",
1004 reply
.r
.chan_id
, reply
.r
.header_type
);
1008 /* Transport level error */
1009 if (errno
== EPIPE
|| errno
== ECONNRESET
)
1013 ERR("incorrect message size: %zd\n", len
);
1020 * Set socket reciving timeout.
1022 int ustcomm_setsockopt_rcv_timeout(int sock
, unsigned int msec
)
1027 tv
.tv_sec
= msec
/ 1000;
1028 tv
.tv_usec
= (msec
* 1000 % 1000000);
1030 ret
= setsockopt(sock
, SOL_SOCKET
, SO_RCVTIMEO
, &tv
, sizeof(tv
));
1032 PERROR("setsockopt SO_RCVTIMEO");
1040 * Set socket sending timeout.
1042 int ustcomm_setsockopt_snd_timeout(int sock
, unsigned int msec
)
1047 tv
.tv_sec
= msec
/ 1000;
1048 tv
.tv_usec
= (msec
* 1000) % 1000000;
1050 ret
= setsockopt(sock
, SOL_SOCKET
, SO_SNDTIMEO
, &tv
, sizeof(tv
));
1052 PERROR("setsockopt SO_SNDTIMEO");