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>
38 #include <lttng/ust-error.h>
39 #include <lttng/ust-events.h>
40 #include <lttng/ust-dynamic-type.h>
41 #include <usterr-signal-safe.h>
43 #include "../liblttng-ust/compat.h"
45 #define USTCOMM_CODE_OFFSET(code) \
46 (code == LTTNG_UST_OK ? 0 : (code - LTTNG_UST_ERR + 1))
48 #define USTCOMM_MAX_SEND_FDS 4
51 ssize_t
count_fields_recursive(size_t nr_fields
,
52 const struct lttng_event_field
*lttng_fields
);
54 int serialize_one_field(struct lttng_session
*session
,
55 struct ustctl_field
*fields
, size_t *iter_output
,
56 const struct lttng_event_field
*lf
);
58 int serialize_fields(struct lttng_session
*session
,
59 struct ustctl_field
*ustctl_fields
,
60 size_t *iter_output
, size_t nr_lttng_fields
,
61 const struct lttng_event_field
*lttng_fields
);
64 * Human readable error message.
66 static const char *ustcomm_readable_code
[] = {
67 [ USTCOMM_CODE_OFFSET(LTTNG_UST_OK
) ] = "Success",
68 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR
) ] = "Unknown error",
69 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_NOENT
) ] = "No entry",
70 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_EXIST
) ] = "Object already exists",
71 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL
) ] = "Invalid argument",
72 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PERM
) ] = "Permission denied",
73 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_NOSYS
) ] = "Not implemented",
74 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_EXITING
) ] = "Process is exiting",
76 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_MAGIC
) ] = "Invalid magic number",
77 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_SOCKET_TYPE
) ] = "Invalid socket type",
78 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_UNSUP_MAJOR
) ] = "Unsupported major version",
79 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PEERCRED
) ] = "Cannot get unix socket peer credentials",
80 [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PEERCRED_PID
) ] = "Peer credentials PID is invalid. Socket appears to belong to a distinct, non-nested pid namespace.",
86 * Receives positive error value.
87 * Return ptr to string representing a human readable
88 * error code from the ustcomm_return_code enum.
90 const char *lttng_ust_strerror(int code
)
92 if (code
== LTTNG_UST_OK
)
93 return ustcomm_readable_code
[USTCOMM_CODE_OFFSET(code
)];
94 if (code
< LTTNG_UST_ERR
)
95 return strerror(code
);
96 if (code
>= LTTNG_UST_ERR_NR
)
98 return ustcomm_readable_code
[USTCOMM_CODE_OFFSET(code
)];
102 * ustcomm_connect_unix_sock
104 * Connect to unix socket using the path name.
106 * Caller handles FD tracker.
108 int ustcomm_connect_unix_sock(const char *pathname
, long timeout
)
110 struct sockaddr_un sun
;
114 * libust threads require the close-on-exec flag for all
115 * resources so it does not leak file descriptors upon exec.
116 * SOCK_CLOEXEC is not used since it is linux specific.
118 fd
= socket(PF_UNIX
, SOCK_STREAM
, 0);
125 /* Give at least 10ms. */
128 ret
= ustcomm_setsockopt_snd_timeout(fd
, timeout
);
130 WARN("Error setting connect socket send timeout");
133 ret
= fcntl(fd
, F_SETFD
, FD_CLOEXEC
);
140 memset(&sun
, 0, sizeof(sun
));
141 sun
.sun_family
= AF_UNIX
;
142 strncpy(sun
.sun_path
, pathname
, sizeof(sun
.sun_path
));
143 sun
.sun_path
[sizeof(sun
.sun_path
) - 1] = '\0';
145 ret
= connect(fd
, (struct sockaddr
*) &sun
, sizeof(sun
));
148 * Don't print message on connect ENOENT error, because
149 * connect is used in normal execution to detect if
150 * sessiond is alive. ENOENT is when the unix socket
151 * file does not exist, and ECONNREFUSED is when the
152 * file exists but no sessiond is listening.
154 if (errno
!= ECONNREFUSED
&& errno
!= ECONNRESET
155 && errno
!= ENOENT
&& errno
!= EACCES
)
158 if (ret
== -ECONNREFUSED
|| ret
== -ECONNRESET
)
170 closeret
= close(fd
);
179 * ustcomm_accept_unix_sock
181 * Do an accept(2) on the sock and return the
182 * new file descriptor. The socket MUST be bind(2) before.
184 int ustcomm_accept_unix_sock(int sock
)
187 struct sockaddr_un sun
;
191 new_fd
= accept(sock
, (struct sockaddr
*) &sun
, &len
);
193 if (errno
!= ECONNABORTED
)
196 if (new_fd
== -ECONNABORTED
)
203 * ustcomm_create_unix_sock
205 * Creates a AF_UNIX local socket using pathname
206 * bind the socket upon creation and return the fd.
208 int ustcomm_create_unix_sock(const char *pathname
)
210 struct sockaddr_un sun
;
213 /* Create server socket */
214 if ((fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) < 0) {
220 memset(&sun
, 0, sizeof(sun
));
221 sun
.sun_family
= AF_UNIX
;
222 strncpy(sun
.sun_path
, pathname
, sizeof(sun
.sun_path
));
223 sun
.sun_path
[sizeof(sun
.sun_path
) - 1] = '\0';
225 /* Unlink the old file if present */
226 (void) unlink(pathname
);
227 ret
= bind(fd
, (struct sockaddr
*) &sun
, sizeof(sun
));
240 closeret
= close(fd
);
250 * ustcomm_listen_unix_sock
252 * Make the socket listen using LTTNG_UST_COMM_MAX_LISTEN.
254 int ustcomm_listen_unix_sock(int sock
)
258 ret
= listen(sock
, LTTNG_UST_COMM_MAX_LISTEN
);
268 * ustcomm_close_unix_sock
270 * Shutdown cleanly a unix socket.
272 * Handles fd tracker internally.
274 int ustcomm_close_unix_sock(int sock
)
278 lttng_ust_lock_fd_tracker();
281 lttng_ust_delete_fd_from_tracker(sock
);
286 lttng_ust_unlock_fd_tracker();
292 * ustcomm_recv_unix_sock
294 * Receive data of size len in put that data into
295 * the buf param. Using recvmsg API.
296 * Return the size of received data.
297 * Return 0 on orderly shutdown.
299 ssize_t
ustcomm_recv_unix_sock(int sock
, void *buf
, size_t len
)
306 memset(&msg
, 0, sizeof(msg
));
308 iov
[0].iov_base
= buf
;
309 iov
[0].iov_len
= len
;
314 len_last
= iov
[0].iov_len
;
315 ret
= recvmsg(sock
, &msg
, 0);
317 iov
[0].iov_base
+= ret
;
318 iov
[0].iov_len
-= ret
;
319 assert(ret
<= len_last
);
321 } while ((ret
> 0 && ret
< len_last
) || (ret
< 0 && errno
== EINTR
));
326 if (errno
!= EPIPE
&& errno
!= ECONNRESET
&& errno
!= ECONNREFUSED
)
329 if (ret
== -ECONNRESET
|| ret
== -ECONNREFUSED
)
332 shutret
= shutdown(sock
, SHUT_RDWR
);
334 ERR("Socket shutdown error");
335 } else if (ret
> 0) {
338 /* ret = 0 means an orderly shutdown. */
344 * ustcomm_send_unix_sock
346 * Send buf data of size len. Using sendmsg API.
347 * Return the size of sent data.
349 ssize_t
ustcomm_send_unix_sock(int sock
, const void *buf
, size_t len
)
355 memset(&msg
, 0, sizeof(msg
));
357 iov
[0].iov_base
= (void *) buf
;
358 iov
[0].iov_len
= len
;
363 * Using the MSG_NOSIGNAL when sending data from sessiond to
364 * libust, so libust does not receive an unhandled SIGPIPE or
365 * SIGURG. The sessiond receiver side can be made more resilient
366 * by ignoring SIGPIPE, but we don't have this luxury on the
370 ret
= sendmsg(sock
, &msg
, MSG_NOSIGNAL
);
371 } while (ret
< 0 && errno
== EINTR
);
376 if (errno
!= EPIPE
&& errno
!= ECONNRESET
)
379 if (ret
== -ECONNRESET
)
382 shutret
= shutdown(sock
, SHUT_RDWR
);
384 ERR("Socket shutdown error");
391 * Send a message accompanied by fd(s) over a unix socket.
393 * Returns the size of data sent, or negative error value.
395 ssize_t
ustcomm_send_fds_unix_sock(int sock
, int *fds
, size_t nb_fd
)
398 struct cmsghdr
*cmptr
;
401 unsigned int sizeof_fds
= nb_fd
* sizeof(int);
402 char tmp
[CMSG_SPACE(sizeof_fds
)];
405 memset(&msg
, 0, sizeof(msg
));
406 memset(tmp
, 0, CMSG_SPACE(sizeof_fds
) * sizeof(char));
408 if (nb_fd
> USTCOMM_MAX_SEND_FDS
)
411 msg
.msg_control
= (caddr_t
)tmp
;
412 msg
.msg_controllen
= CMSG_LEN(sizeof_fds
);
414 cmptr
= CMSG_FIRSTHDR(&msg
);
417 cmptr
->cmsg_level
= SOL_SOCKET
;
418 cmptr
->cmsg_type
= SCM_RIGHTS
;
419 cmptr
->cmsg_len
= CMSG_LEN(sizeof_fds
);
420 memcpy(CMSG_DATA(cmptr
), fds
, sizeof_fds
);
421 /* Sum of the length of all control messages in the buffer: */
422 msg
.msg_controllen
= cmptr
->cmsg_len
;
424 iov
[0].iov_base
= &dummy
;
430 ret
= sendmsg(sock
, &msg
, MSG_NOSIGNAL
);
431 } while (ret
< 0 && errno
== EINTR
);
434 * We consider EPIPE and ECONNRESET as expected.
436 if (errno
!= EPIPE
&& errno
!= ECONNRESET
) {
440 if (ret
== -ECONNRESET
)
447 * Recv a message accompanied by fd(s) from a unix socket.
449 * Expect at most "nb_fd" file descriptors. Returns the number of fd
450 * actually received in nb_fd.
451 * Returns -EPIPE on orderly shutdown.
453 ssize_t
ustcomm_recv_fds_unix_sock(int sock
, int *fds
, size_t nb_fd
)
457 struct cmsghdr
*cmsg
;
458 size_t sizeof_fds
= nb_fd
* sizeof(int);
459 char recv_fd
[CMSG_SPACE(sizeof_fds
)];
464 memset(&msg
, 0, sizeof(msg
));
466 /* Prepare to receive the structures */
467 iov
[0].iov_base
= &dummy
;
471 msg
.msg_control
= recv_fd
;
472 msg
.msg_controllen
= sizeof(recv_fd
);
475 ret
= recvmsg(sock
, &msg
, 0);
476 } while (ret
< 0 && errno
== EINTR
);
478 if (errno
!= EPIPE
&& errno
!= ECONNRESET
) {
479 PERROR("recvmsg fds");
482 if (ret
== -ECONNRESET
)
487 /* orderly shutdown */
492 ERR("Error: Received %zd bytes, expected %d\n",
496 if (msg
.msg_flags
& MSG_CTRUNC
) {
497 ERR("Error: Control message truncated.\n");
501 cmsg
= CMSG_FIRSTHDR(&msg
);
503 ERR("Error: Invalid control message header\n");
507 if (cmsg
->cmsg_level
!= SOL_SOCKET
|| cmsg
->cmsg_type
!= SCM_RIGHTS
) {
508 ERR("Didn't received any fd\n");
512 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof_fds
)) {
513 ERR("Error: Received %zu bytes of ancillary data, expected %zu\n",
514 (size_t) cmsg
->cmsg_len
, (size_t) CMSG_LEN(sizeof_fds
));
519 memcpy(fds
, CMSG_DATA(cmsg
), sizeof_fds
);
522 for (i
= 0; i
< nb_fd
; i
++) {
523 ret
= fcntl(fds
[i
], F_SETFD
, FD_CLOEXEC
);
525 PERROR("fcntl failed to set FD_CLOEXEC on fd %d",
535 int ustcomm_send_app_msg(int sock
, struct ustcomm_ust_msg
*lum
)
539 len
= ustcomm_send_unix_sock(sock
, lum
, sizeof(*lum
));
547 ERR("incorrect message size: %zd\n", len
);
554 int ustcomm_recv_app_reply(int sock
, struct ustcomm_ust_reply
*lur
,
555 uint32_t expected_handle
, uint32_t expected_cmd
)
559 memset(lur
, 0, sizeof(*lur
));
560 len
= ustcomm_recv_unix_sock(sock
, lur
, sizeof(*lur
));
562 case 0: /* orderly shutdown */
568 if (lur
->handle
!= expected_handle
) {
569 ERR("Unexpected result message handle: "
570 "expected: %u vs received: %u\n",
571 expected_handle
, lur
->handle
);
574 if (lur
->cmd
!= expected_cmd
) {
575 ERR("Unexpected result message command "
576 "expected: %u vs received: %u\n",
577 expected_cmd
, lur
->cmd
);
583 return lur
->ret_code
;
588 ERR("incorrect message size: %zd\n", len
);
594 int ustcomm_send_app_cmd(int sock
,
595 struct ustcomm_ust_msg
*lum
,
596 struct ustcomm_ust_reply
*lur
)
600 ret
= ustcomm_send_app_msg(sock
, lum
);
603 ret
= ustcomm_recv_app_reply(sock
, lur
, lum
->handle
, lum
->cmd
);
610 * chan_data is allocated internally if this function returns the
613 ssize_t
ustcomm_recv_channel_from_sessiond(int sock
,
614 void **_chan_data
, uint64_t var_len
,
621 if (var_len
> LTTNG_UST_CHANNEL_DATA_MAX_LEN
) {
625 /* Receive variable length data */
626 chan_data
= zmalloc(var_len
);
631 len
= ustcomm_recv_unix_sock(sock
, chan_data
, var_len
);
632 if (len
!= var_len
) {
636 lttng_ust_lock_fd_tracker();
637 nr_fd
= ustcomm_recv_fds_unix_sock(sock
, &wakeup_fd
, 1);
639 lttng_ust_unlock_fd_tracker();
649 ret
= lttng_ust_add_fd_to_tracker(wakeup_fd
);
651 ret
= close(wakeup_fd
);
653 PERROR("close on wakeup_fd");
656 lttng_ust_unlock_fd_tracker();
661 lttng_ust_unlock_fd_tracker();
663 *_chan_data
= chan_data
;
673 ssize_t
ustcomm_recv_event_notifier_notif_fd_from_sessiond(int sock
,
674 int *_event_notifier_notif_fd
)
677 int event_notifier_notif_fd
, ret
;
679 /* Receive event_notifier notification fd */
680 lttng_ust_lock_fd_tracker();
681 nr_fd
= ustcomm_recv_fds_unix_sock(sock
, &event_notifier_notif_fd
, 1);
683 lttng_ust_unlock_fd_tracker();
693 ret
= lttng_ust_add_fd_to_tracker(event_notifier_notif_fd
);
695 ret
= close(event_notifier_notif_fd
);
697 PERROR("close on event_notifier notif fd");
700 lttng_ust_unlock_fd_tracker();
704 *_event_notifier_notif_fd
= ret
;
705 lttng_ust_unlock_fd_tracker();
713 int ustcomm_recv_stream_from_sessiond(int sock
,
714 uint64_t *memory_map_size
,
715 int *shm_fd
, int *wakeup_fd
)
721 /* recv shm fd and wakeup fd */
722 lttng_ust_lock_fd_tracker();
723 len
= ustcomm_recv_fds_unix_sock(sock
, fds
, 2);
725 lttng_ust_unlock_fd_tracker();
735 ret
= lttng_ust_add_fd_to_tracker(fds
[0]);
739 PERROR("close on received shm_fd");
742 lttng_ust_unlock_fd_tracker();
747 ret
= lttng_ust_add_fd_to_tracker(fds
[1]);
749 ret
= close(*shm_fd
);
751 PERROR("close on shm_fd");
756 PERROR("close on received wakeup_fd");
759 lttng_ust_unlock_fd_tracker();
763 lttng_ust_unlock_fd_tracker();
770 ssize_t
ustcomm_recv_counter_from_sessiond(int sock
,
771 void **_counter_data
, uint64_t var_len
)
776 if (var_len
> LTTNG_UST_COUNTER_DATA_MAX_LEN
) {
780 /* Receive variable length data */
781 counter_data
= zmalloc(var_len
);
786 len
= ustcomm_recv_unix_sock(sock
, counter_data
, var_len
);
787 if (len
!= var_len
) {
790 *_counter_data
= counter_data
;
800 int ustcomm_recv_counter_shm_from_sessiond(int sock
,
808 lttng_ust_lock_fd_tracker();
809 len
= ustcomm_recv_fds_unix_sock(sock
, fds
, 1);
811 lttng_ust_unlock_fd_tracker();
821 ret
= lttng_ust_add_fd_to_tracker(fds
[0]);
825 PERROR("close on received shm_fd");
828 lttng_ust_unlock_fd_tracker();
832 lttng_ust_unlock_fd_tracker();
840 * Returns 0 on success, negative error value on error.
842 int ustcomm_send_reg_msg(int sock
,
843 enum ustctl_socket_type type
,
844 uint32_t bits_per_long
,
845 uint32_t uint8_t_alignment
,
846 uint32_t uint16_t_alignment
,
847 uint32_t uint32_t_alignment
,
848 uint32_t uint64_t_alignment
,
849 uint32_t long_alignment
)
852 struct ustctl_reg_msg reg_msg
;
854 reg_msg
.magic
= LTTNG_UST_COMM_MAGIC
;
855 reg_msg
.major
= LTTNG_UST_ABI_MAJOR_VERSION
;
856 reg_msg
.minor
= LTTNG_UST_ABI_MINOR_VERSION
;
857 reg_msg
.pid
= getpid();
858 reg_msg
.ppid
= getppid();
859 reg_msg
.uid
= getuid();
860 reg_msg
.gid
= getgid();
861 reg_msg
.bits_per_long
= bits_per_long
;
862 reg_msg
.uint8_t_alignment
= uint8_t_alignment
;
863 reg_msg
.uint16_t_alignment
= uint16_t_alignment
;
864 reg_msg
.uint32_t_alignment
= uint32_t_alignment
;
865 reg_msg
.uint64_t_alignment
= uint64_t_alignment
;
866 reg_msg
.long_alignment
= long_alignment
;
867 reg_msg
.socket_type
= type
;
868 lttng_pthread_getname_np(reg_msg
.name
, LTTNG_UST_ABI_PROCNAME_LEN
);
869 memset(reg_msg
.padding
, 0, sizeof(reg_msg
.padding
));
871 len
= ustcomm_send_unix_sock(sock
, ®_msg
, sizeof(reg_msg
));
872 if (len
> 0 && len
!= sizeof(reg_msg
))
880 ssize_t
count_one_type(const struct lttng_type
*lt
)
891 return count_fields_recursive(lt
->u
.legacy
._struct
.nr_fields
,
892 lt
->u
.legacy
._struct
.fields
) + 1;
893 case atype_enum_nestable
:
894 return count_one_type(lt
->u
.enum_nestable
.container_type
) + 1;
895 case atype_array_nestable
:
896 return count_one_type(lt
->u
.array_nestable
.elem_type
) + 1;
897 case atype_sequence_nestable
:
898 return count_one_type(lt
->u
.sequence_nestable
.elem_type
) + 1;
899 case atype_struct_nestable
:
900 return count_fields_recursive(lt
->u
.struct_nestable
.nr_fields
,
901 lt
->u
.struct_nestable
.fields
) + 1;
905 const struct lttng_event_field
*choices
;
909 ret
= lttng_ust_dynamic_type_choices(&nr_choices
,
914 * Two fields for enum, one field for variant, and
915 * one field per choice.
917 return count_fields_recursive(nr_choices
, choices
) + 3;
927 ssize_t
count_fields_recursive(size_t nr_fields
,
928 const struct lttng_event_field
*lttng_fields
)
931 ssize_t ret
, count
= 0;
933 for (i
= 0; i
< nr_fields
; i
++) {
934 const struct lttng_event_field
*lf
;
936 lf
= <tng_fields
[i
];
937 /* skip 'nowrite' fields */
940 ret
= count_one_type(&lf
->type
);
942 return ret
; /* error */
949 ssize_t
count_ctx_fields_recursive(size_t nr_fields
,
950 const struct lttng_ctx_field
*lttng_fields
)
953 ssize_t ret
, count
= 0;
955 for (i
= 0; i
< nr_fields
; i
++) {
956 const struct lttng_event_field
*lf
;
958 lf
= <tng_fields
[i
].event_field
;
959 /* skip 'nowrite' fields */
962 ret
= count_one_type(&lf
->type
);
964 return ret
; /* error */
971 int serialize_string_encoding(int32_t *ue
,
972 enum lttng_string_encodings le
)
975 case lttng_encode_none
:
976 *ue
= ustctl_encode_none
;
978 case lttng_encode_UTF8
:
979 *ue
= ustctl_encode_UTF8
;
981 case lttng_encode_ASCII
:
982 *ue
= ustctl_encode_ASCII
;
991 int serialize_integer_type(struct ustctl_integer_type
*uit
,
992 const struct lttng_integer_type
*lit
)
996 uit
->size
= lit
->size
;
997 uit
->signedness
= lit
->signedness
;
998 uit
->reverse_byte_order
= lit
->reverse_byte_order
;
999 uit
->base
= lit
->base
;
1000 if (serialize_string_encoding(&encoding
, lit
->encoding
))
1002 uit
->encoding
= encoding
;
1003 uit
->alignment
= lit
->alignment
;
1008 int serialize_basic_type(struct lttng_session
*session
,
1009 enum ustctl_abstract_types
*uatype
,
1010 enum lttng_abstract_types atype
,
1011 union _ustctl_basic_type
*ubt
,
1012 const union _lttng_basic_type
*lbt
)
1017 if (serialize_integer_type(&ubt
->integer
, &lbt
->integer
))
1019 *uatype
= ustctl_atype_integer
;
1026 if (serialize_string_encoding(&encoding
, lbt
->string
.encoding
))
1028 ubt
->string
.encoding
= encoding
;
1029 *uatype
= ustctl_atype_string
;
1034 struct ustctl_float_type
*uft
;
1035 const struct lttng_float_type
*lft
;
1039 uft
->exp_dig
= lft
->exp_dig
;
1040 uft
->mant_dig
= lft
->mant_dig
;
1041 uft
->alignment
= lft
->alignment
;
1042 uft
->reverse_byte_order
= lft
->reverse_byte_order
;
1043 *uatype
= ustctl_atype_float
;
1048 strncpy(ubt
->enumeration
.name
, lbt
->enumeration
.desc
->name
,
1049 LTTNG_UST_SYM_NAME_LEN
);
1050 ubt
->enumeration
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1051 if (serialize_integer_type(&ubt
->enumeration
.container_type
,
1052 &lbt
->enumeration
.container_type
))
1055 const struct lttng_enum
*_enum
;
1057 _enum
= lttng_ust_enum_get_from_desc(session
, lbt
->enumeration
.desc
);
1060 ubt
->enumeration
.id
= _enum
->id
;
1062 ubt
->enumeration
.id
= -1ULL;
1064 *uatype
= ustctl_atype_enum
;
1068 case atype_array_nestable
:
1069 case atype_sequence
:
1070 case atype_sequence_nestable
:
1071 case atype_enum_nestable
:
1079 int serialize_dynamic_type(struct lttng_session
*session
,
1080 struct ustctl_field
*fields
, size_t *iter_output
,
1081 const char *field_name
)
1083 const struct lttng_event_field
*choices
;
1084 char tag_field_name
[LTTNG_UST_SYM_NAME_LEN
];
1085 const struct lttng_type
*tag_type
;
1086 const struct lttng_event_field
*tag_field_generic
;
1087 struct lttng_event_field tag_field
= {
1088 .name
= tag_field_name
,
1091 struct ustctl_field
*uf
;
1092 size_t nr_choices
, i
;
1095 tag_field_generic
= lttng_ust_dynamic_type_tag_field();
1096 tag_type
= &tag_field_generic
->type
;
1098 /* Serialize enum field. */
1099 strncpy(tag_field_name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1100 tag_field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1101 strncat(tag_field_name
,
1103 LTTNG_UST_SYM_NAME_LEN
- strlen(tag_field_name
) - 1);
1104 tag_field
.type
= *tag_type
;
1105 ret
= serialize_one_field(session
, fields
, iter_output
,
1110 /* Serialize variant field. */
1111 uf
= &fields
[*iter_output
];
1112 ret
= lttng_ust_dynamic_type_choices(&nr_choices
, &choices
);
1116 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1117 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1118 uf
->type
.atype
= ustctl_atype_variant
;
1119 uf
->type
.u
.variant_nestable
.nr_choices
= nr_choices
;
1120 strncpy(uf
->type
.u
.variant_nestable
.tag_name
,
1122 LTTNG_UST_SYM_NAME_LEN
);
1123 uf
->type
.u
.variant_nestable
.tag_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1124 uf
->type
.u
.variant_nestable
.alignment
= 0;
1127 /* Serialize choice fields after variant. */
1128 for (i
= 0; i
< nr_choices
; i
++) {
1129 ret
= serialize_one_field(session
, fields
,
1130 iter_output
, &choices
[i
]);
1138 int serialize_one_type(struct lttng_session
*session
,
1139 struct ustctl_field
*fields
, size_t *iter_output
,
1140 const char *field_name
, const struct lttng_type
*lt
)
1145 * Serializing a type (rather than a field) generates a ustctl_field
1146 * entry with 0-length name.
1149 switch (lt
->atype
) {
1155 struct ustctl_field
*uf
= &fields
[*iter_output
];
1156 struct ustctl_type
*ut
= &uf
->type
;
1157 enum ustctl_abstract_types atype
;
1160 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1161 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1165 ret
= serialize_basic_type(session
, &atype
, lt
->atype
,
1166 &ut
->u
.legacy
.basic
, <
->u
.legacy
.basic
);
1175 struct ustctl_field
*uf
= &fields
[*iter_output
];
1176 struct ustctl_type
*ut
= &uf
->type
;
1177 struct ustctl_basic_type
*ubt
;
1178 const struct lttng_basic_type
*lbt
;
1179 enum ustctl_abstract_types atype
;
1182 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1183 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1187 ut
->atype
= ustctl_atype_array
;
1188 ubt
= &ut
->u
.legacy
.array
.elem_type
;
1189 lbt
= <
->u
.legacy
.array
.elem_type
;
1190 ut
->u
.legacy
.array
.length
= lt
->u
.legacy
.array
.length
;
1191 ret
= serialize_basic_type(session
, &atype
, lbt
->atype
,
1192 &ubt
->u
.basic
, &lbt
->u
.basic
);
1199 case atype_array_nestable
:
1201 struct ustctl_field
*uf
= &fields
[*iter_output
];
1202 struct ustctl_type
*ut
= &uf
->type
;
1205 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1206 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1210 ut
->atype
= ustctl_atype_array_nestable
;
1211 ut
->u
.array_nestable
.length
= lt
->u
.array_nestable
.length
;
1212 ut
->u
.array_nestable
.alignment
= lt
->u
.array_nestable
.alignment
;
1215 ret
= serialize_one_type(session
, fields
, iter_output
, NULL
,
1216 lt
->u
.array_nestable
.elem_type
);
1221 case atype_sequence
:
1223 struct ustctl_field
*uf
= &fields
[*iter_output
];
1224 struct ustctl_type
*ut
= &uf
->type
;
1225 struct ustctl_basic_type
*ubt
;
1226 const struct lttng_basic_type
*lbt
;
1227 enum ustctl_abstract_types atype
;
1230 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1231 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1235 uf
->type
.atype
= ustctl_atype_sequence
;
1236 ubt
= &ut
->u
.legacy
.sequence
.length_type
;
1237 lbt
= <
->u
.legacy
.sequence
.length_type
;
1238 ret
= serialize_basic_type(session
, &atype
, lbt
->atype
,
1239 &ubt
->u
.basic
, &lbt
->u
.basic
);
1243 ubt
= &ut
->u
.legacy
.sequence
.elem_type
;
1244 lbt
= <
->u
.legacy
.sequence
.elem_type
;
1245 ret
= serialize_basic_type(session
, &atype
, lbt
->atype
,
1246 &ubt
->u
.basic
, &lbt
->u
.basic
);
1253 case atype_sequence_nestable
:
1255 struct ustctl_field
*uf
= &fields
[*iter_output
];
1256 struct ustctl_type
*ut
= &uf
->type
;
1259 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1260 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1264 ut
->atype
= ustctl_atype_sequence_nestable
;
1265 strncpy(ut
->u
.sequence_nestable
.length_name
,
1266 lt
->u
.sequence_nestable
.length_name
,
1267 LTTNG_UST_SYM_NAME_LEN
);
1268 ut
->u
.sequence_nestable
.length_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1269 ut
->u
.sequence_nestable
.alignment
= lt
->u
.sequence_nestable
.alignment
;
1272 ret
= serialize_one_type(session
, fields
, iter_output
, NULL
,
1273 lt
->u
.sequence_nestable
.elem_type
);
1280 ret
= serialize_dynamic_type(session
, fields
, iter_output
,
1288 struct ustctl_field
*uf
= &fields
[*iter_output
];
1291 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1292 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1296 uf
->type
.atype
= ustctl_atype_struct
;
1297 uf
->type
.u
.legacy
._struct
.nr_fields
= lt
->u
.legacy
._struct
.nr_fields
;
1300 ret
= serialize_fields(session
, fields
, iter_output
,
1301 lt
->u
.legacy
._struct
.nr_fields
,
1302 lt
->u
.legacy
._struct
.fields
);
1307 case atype_struct_nestable
:
1309 struct ustctl_field
*uf
= &fields
[*iter_output
];
1312 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1313 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1317 uf
->type
.atype
= ustctl_atype_struct_nestable
;
1318 uf
->type
.u
.struct_nestable
.nr_fields
= lt
->u
.struct_nestable
.nr_fields
;
1319 uf
->type
.u
.struct_nestable
.alignment
= lt
->u
.struct_nestable
.alignment
;
1322 ret
= serialize_fields(session
, fields
, iter_output
,
1323 lt
->u
.struct_nestable
.nr_fields
,
1324 lt
->u
.struct_nestable
.fields
);
1329 case atype_enum_nestable
:
1331 struct ustctl_field
*uf
= &fields
[*iter_output
];
1332 struct ustctl_type
*ut
= &uf
->type
;
1335 strncpy(uf
->name
, field_name
, LTTNG_UST_SYM_NAME_LEN
);
1336 uf
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1340 strncpy(ut
->u
.enum_nestable
.name
, lt
->u
.enum_nestable
.desc
->name
,
1341 LTTNG_UST_SYM_NAME_LEN
);
1342 ut
->u
.enum_nestable
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1343 ut
->atype
= ustctl_atype_enum_nestable
;
1346 ret
= serialize_one_type(session
, fields
, iter_output
, NULL
,
1347 lt
->u
.enum_nestable
.container_type
);
1351 const struct lttng_enum
*_enum
;
1353 _enum
= lttng_ust_enum_get_from_desc(session
, lt
->u
.enum_nestable
.desc
);
1356 ut
->u
.enum_nestable
.id
= _enum
->id
;
1358 ut
->u
.enum_nestable
.id
= -1ULL;
1369 int serialize_one_field(struct lttng_session
*session
,
1370 struct ustctl_field
*fields
, size_t *iter_output
,
1371 const struct lttng_event_field
*lf
)
1373 /* skip 'nowrite' fields */
1377 return serialize_one_type(session
, fields
, iter_output
, lf
->name
, &lf
->type
);
1381 int serialize_fields(struct lttng_session
*session
,
1382 struct ustctl_field
*ustctl_fields
,
1383 size_t *iter_output
, size_t nr_lttng_fields
,
1384 const struct lttng_event_field
*lttng_fields
)
1389 for (i
= 0; i
< nr_lttng_fields
; i
++) {
1390 ret
= serialize_one_field(session
, ustctl_fields
,
1391 iter_output
, <tng_fields
[i
]);
1399 int alloc_serialize_fields(struct lttng_session
*session
,
1400 size_t *_nr_write_fields
,
1401 struct ustctl_field
**ustctl_fields
,
1403 const struct lttng_event_field
*lttng_fields
)
1405 struct ustctl_field
*fields
;
1407 size_t iter_output
= 0;
1408 ssize_t nr_write_fields
;
1410 nr_write_fields
= count_fields_recursive(nr_fields
, lttng_fields
);
1411 if (nr_write_fields
< 0) {
1412 return (int) nr_write_fields
;
1415 fields
= zmalloc(nr_write_fields
* sizeof(*fields
));
1419 ret
= serialize_fields(session
, fields
, &iter_output
, nr_fields
,
1424 *_nr_write_fields
= nr_write_fields
;
1425 *ustctl_fields
= fields
;
1434 int serialize_entries(struct ustctl_enum_entry
**_entries
,
1436 const struct lttng_enum_entry
*lttng_entries
)
1438 struct ustctl_enum_entry
*entries
;
1441 /* Serialize the entries */
1442 entries
= zmalloc(nr_entries
* sizeof(*entries
));
1445 for (i
= 0; i
< nr_entries
; i
++) {
1446 struct ustctl_enum_entry
*uentry
;
1447 const struct lttng_enum_entry
*lentry
;
1449 uentry
= &entries
[i
];
1450 lentry
= <tng_entries
[i
];
1452 uentry
->start
.value
= lentry
->start
.value
;
1453 uentry
->start
.signedness
= lentry
->start
.signedness
;
1454 uentry
->end
.value
= lentry
->end
.value
;
1455 uentry
->end
.signedness
= lentry
->end
.signedness
;
1456 strncpy(uentry
->string
, lentry
->string
, LTTNG_UST_SYM_NAME_LEN
);
1457 uentry
->string
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1459 if (lentry
->u
.extra
.options
& LTTNG_ENUM_ENTRY_OPTION_IS_AUTO
) {
1460 uentry
->u
.extra
.options
|=
1461 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO
;
1464 *_entries
= entries
;
1469 int serialize_ctx_fields(struct lttng_session
*session
,
1470 size_t *_nr_write_fields
,
1471 struct ustctl_field
**ustctl_fields
,
1473 const struct lttng_ctx_field
*lttng_fields
)
1475 struct ustctl_field
*fields
;
1477 size_t i
, iter_output
= 0;
1478 ssize_t nr_write_fields
;
1480 nr_write_fields
= count_ctx_fields_recursive(nr_fields
,
1482 if (nr_write_fields
< 0) {
1483 return (int) nr_write_fields
;
1486 fields
= zmalloc(nr_write_fields
* sizeof(*fields
));
1490 for (i
= 0; i
< nr_fields
; i
++) {
1491 ret
= serialize_one_field(session
, fields
, &iter_output
,
1492 <tng_fields
[i
].event_field
);
1497 *_nr_write_fields
= nr_write_fields
;
1498 *ustctl_fields
= fields
;
1507 * Returns 0 on success, negative error value on error.
1509 int ustcomm_register_event(int sock
,
1510 struct lttng_session
*session
,
1511 int session_objd
, /* session descriptor */
1512 int channel_objd
, /* channel descriptor */
1513 const char *event_name
, /* event name (input) */
1515 const char *signature
, /* event signature (input) */
1516 size_t nr_fields
, /* fields */
1517 const struct lttng_event_field
*lttng_fields
,
1518 const char *model_emf_uri
,
1519 uint32_t *id
) /* event id (output) */
1523 struct ustcomm_notify_hdr header
;
1524 struct ustcomm_notify_event_msg m
;
1527 struct ustcomm_notify_hdr header
;
1528 struct ustcomm_notify_event_reply r
;
1530 size_t signature_len
, fields_len
, model_emf_uri_len
;
1531 struct ustctl_field
*fields
= NULL
;
1532 size_t nr_write_fields
= 0;
1535 memset(&msg
, 0, sizeof(msg
));
1536 msg
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
1537 msg
.m
.session_objd
= session_objd
;
1538 msg
.m
.channel_objd
= channel_objd
;
1539 strncpy(msg
.m
.event_name
, event_name
, LTTNG_UST_SYM_NAME_LEN
);
1540 msg
.m
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1541 msg
.m
.loglevel
= loglevel
;
1542 signature_len
= strlen(signature
) + 1;
1543 msg
.m
.signature_len
= signature_len
;
1545 /* Calculate fields len, serialize fields. */
1546 if (nr_fields
> 0) {
1547 ret
= alloc_serialize_fields(session
, &nr_write_fields
, &fields
,
1548 nr_fields
, lttng_fields
);
1553 fields_len
= sizeof(*fields
) * nr_write_fields
;
1554 msg
.m
.fields_len
= fields_len
;
1555 if (model_emf_uri
) {
1556 model_emf_uri_len
= strlen(model_emf_uri
) + 1;
1558 model_emf_uri_len
= 0;
1560 msg
.m
.model_emf_uri_len
= model_emf_uri_len
;
1562 len
= ustcomm_send_unix_sock(sock
, &msg
, sizeof(msg
));
1563 if (len
> 0 && len
!= sizeof(msg
)) {
1572 /* send signature */
1573 len
= ustcomm_send_unix_sock(sock
, signature
, signature_len
);
1574 if (len
> 0 && len
!= signature_len
) {
1584 if (fields_len
> 0) {
1585 len
= ustcomm_send_unix_sock(sock
, fields
, fields_len
);
1586 if (len
> 0 && len
!= fields_len
) {
1597 if (model_emf_uri_len
) {
1598 /* send model_emf_uri */
1599 len
= ustcomm_send_unix_sock(sock
, model_emf_uri
,
1601 if (len
> 0 && len
!= model_emf_uri_len
) {
1610 len
= ustcomm_recv_unix_sock(sock
, &reply
, sizeof(reply
));
1612 case 0: /* orderly shutdown */
1615 if (reply
.header
.notify_cmd
!= msg
.header
.notify_cmd
) {
1616 ERR("Unexpected result message command "
1617 "expected: %u vs received: %u\n",
1618 msg
.header
.notify_cmd
, reply
.header
.notify_cmd
);
1621 if (reply
.r
.ret_code
> 0)
1623 if (reply
.r
.ret_code
< 0)
1624 return reply
.r
.ret_code
;
1625 *id
= reply
.r
.event_id
;
1626 DBG("Sent register event notification for name \"%s\": ret_code %d, event_id %u\n",
1627 event_name
, reply
.r
.ret_code
, reply
.r
.event_id
);
1631 /* Transport level error */
1632 if (errno
== EPIPE
|| errno
== ECONNRESET
)
1636 ERR("incorrect message size: %zd\n", len
);
1642 /* Error path only. */
1649 * Returns 0 on success, negative error value on error.
1650 * Returns -EPIPE or -ECONNRESET if other end has hung up.
1652 int ustcomm_register_enum(int sock
,
1653 int session_objd
, /* session descriptor */
1654 const char *enum_name
, /* enum name (input) */
1655 size_t nr_entries
, /* entries */
1656 const struct lttng_enum_entry
*lttng_entries
,
1661 struct ustcomm_notify_hdr header
;
1662 struct ustcomm_notify_enum_msg m
;
1665 struct ustcomm_notify_hdr header
;
1666 struct ustcomm_notify_enum_reply r
;
1669 struct ustctl_enum_entry
*entries
= NULL
;
1672 memset(&msg
, 0, sizeof(msg
));
1673 msg
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_ENUM
;
1674 msg
.m
.session_objd
= session_objd
;
1675 strncpy(msg
.m
.enum_name
, enum_name
, LTTNG_UST_SYM_NAME_LEN
);
1676 msg
.m
.enum_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1678 /* Calculate entries len, serialize entries. */
1679 if (nr_entries
> 0) {
1680 ret
= serialize_entries(&entries
,
1681 nr_entries
, lttng_entries
);
1686 entries_len
= sizeof(*entries
) * nr_entries
;
1687 msg
.m
.entries_len
= entries_len
;
1689 len
= ustcomm_send_unix_sock(sock
, &msg
, sizeof(msg
));
1690 if (len
> 0 && len
!= sizeof(msg
)) {
1700 if (entries_len
> 0) {
1701 len
= ustcomm_send_unix_sock(sock
, entries
, entries_len
);
1702 if (len
> 0 && len
!= entries_len
) {
1715 len
= ustcomm_recv_unix_sock(sock
, &reply
, sizeof(reply
));
1717 case 0: /* orderly shutdown */
1720 if (reply
.header
.notify_cmd
!= msg
.header
.notify_cmd
) {
1721 ERR("Unexpected result message command "
1722 "expected: %u vs received: %u\n",
1723 msg
.header
.notify_cmd
, reply
.header
.notify_cmd
);
1726 if (reply
.r
.ret_code
> 0)
1728 if (reply
.r
.ret_code
< 0)
1729 return reply
.r
.ret_code
;
1730 *id
= reply
.r
.enum_id
;
1731 DBG("Sent register enum notification for name \"%s\": ret_code %d\n",
1732 enum_name
, reply
.r
.ret_code
);
1736 /* Transport level error */
1737 if (errno
== EPIPE
|| errno
== ECONNRESET
)
1741 ERR("incorrect message size: %zd\n", len
);
1753 * Returns 0 on success, negative error value on error.
1754 * Returns -EPIPE or -ECONNRESET if other end has hung up.
1756 int ustcomm_register_channel(int sock
,
1757 struct lttng_session
*session
,
1758 int session_objd
, /* session descriptor */
1759 int channel_objd
, /* channel descriptor */
1760 size_t nr_ctx_fields
,
1761 const struct lttng_ctx_field
*ctx_fields
,
1762 uint32_t *chan_id
, /* channel id (output) */
1763 int *header_type
) /* header type (output) */
1767 struct ustcomm_notify_hdr header
;
1768 struct ustcomm_notify_channel_msg m
;
1771 struct ustcomm_notify_hdr header
;
1772 struct ustcomm_notify_channel_reply r
;
1775 struct ustctl_field
*fields
= NULL
;
1777 size_t nr_write_fields
= 0;
1779 memset(&msg
, 0, sizeof(msg
));
1780 msg
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
1781 msg
.m
.session_objd
= session_objd
;
1782 msg
.m
.channel_objd
= channel_objd
;
1784 /* Calculate fields len, serialize fields. */
1785 if (nr_ctx_fields
> 0) {
1786 ret
= serialize_ctx_fields(session
, &nr_write_fields
, &fields
,
1787 nr_ctx_fields
, ctx_fields
);
1792 fields_len
= sizeof(*fields
) * nr_write_fields
;
1793 msg
.m
.ctx_fields_len
= fields_len
;
1794 len
= ustcomm_send_unix_sock(sock
, &msg
, sizeof(msg
));
1795 if (len
> 0 && len
!= sizeof(msg
)) {
1805 if (fields_len
> 0) {
1806 len
= ustcomm_send_unix_sock(sock
, fields
, fields_len
);
1808 if (len
> 0 && len
!= fields_len
) {
1818 len
= ustcomm_recv_unix_sock(sock
, &reply
, sizeof(reply
));
1820 case 0: /* orderly shutdown */
1823 if (reply
.header
.notify_cmd
!= msg
.header
.notify_cmd
) {
1824 ERR("Unexpected result message command "
1825 "expected: %u vs received: %u\n",
1826 msg
.header
.notify_cmd
, reply
.header
.notify_cmd
);
1829 if (reply
.r
.ret_code
> 0)
1831 if (reply
.r
.ret_code
< 0)
1832 return reply
.r
.ret_code
;
1833 *chan_id
= reply
.r
.chan_id
;
1834 switch (reply
.r
.header_type
) {
1837 *header_type
= reply
.r
.header_type
;
1840 ERR("Unexpected channel header type %u\n",
1841 reply
.r
.header_type
);
1844 DBG("Sent register channel notification: chan_id %d, header_type %d\n",
1845 reply
.r
.chan_id
, reply
.r
.header_type
);
1849 /* Transport level error */
1850 if (errno
== EPIPE
|| errno
== ECONNRESET
)
1854 ERR("incorrect message size: %zd\n", len
);
1861 * Set socket reciving timeout.
1863 int ustcomm_setsockopt_rcv_timeout(int sock
, unsigned int msec
)
1868 tv
.tv_sec
= msec
/ 1000;
1869 tv
.tv_usec
= (msec
* 1000 % 1000000);
1871 ret
= setsockopt(sock
, SOL_SOCKET
, SO_RCVTIMEO
, &tv
, sizeof(tv
));
1873 PERROR("setsockopt SO_RCVTIMEO");
1881 * Set socket sending timeout.
1883 int ustcomm_setsockopt_snd_timeout(int sock
, unsigned int msec
)
1888 tv
.tv_sec
= msec
/ 1000;
1889 tv
.tv_usec
= (msec
* 1000) % 1000000;
1891 ret
= setsockopt(sock
, SOL_SOCKET
, SO_SNDTIMEO
, &tv
, sizeof(tv
));
1893 PERROR("setsockopt SO_SNDTIMEO");