bin: compile lttng-sessiond as C++
[lttng-tools.git] / src / common / sessiond-comm / inet.c
index d107ced2881f787166c99302f63326dfe6f4499a..93fb19bb51acb611cf9a4fd4d9af2b6532acd5cc 100644 (file)
@@ -1,22 +1,11 @@
 /*
- * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
-#include <assert.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <common/compat/time.h>
 #include <poll.h>
 
 #include <common/common.h>
 #include <common/time.h>
+#include <common/compat/errno.h>
 
 #include "inet.h"
 
@@ -54,7 +43,6 @@ unsigned long lttcomm_inet_tcp_timeout;
 /*
  * Creates an PF_INET socket.
  */
-LTTNG_HIDDEN
 int lttcomm_create_inet_sock(struct lttcomm_sock *sock, int type, int proto)
 {
        int val = 1, ret;
@@ -97,22 +85,19 @@ error:
 /*
  * Bind socket and return.
  */
-LTTNG_HIDDEN
 int lttcomm_bind_inet_sock(struct lttcomm_sock *sock)
 {
-       return bind(sock->fd,
-                       (const struct sockaddr *) ALIGNED_CONST_PTR(
-                                       sock->sockaddr.addr.sin),
-                       sizeof(sock->sockaddr.addr.sin));
+       struct sockaddr_in sockaddr = sock->sockaddr.addr.sin;
+
+       return bind(sock->fd, &sockaddr, sizeof(sockaddr));
 }
 
 static
 int connect_no_timeout(struct lttcomm_sock *sock)
 {
-       return connect(sock->fd,
-                       (const struct sockaddr *) ALIGNED_CONST_PTR(
-                                       sock->sockaddr.addr.sin),
-                       sizeof(sock->sockaddr.addr.sin));
+       struct sockaddr_in sockaddr = sock->sockaddr.addr.sin;
+
+       return connect(sock->fd, &sockaddr, sizeof(sockaddr));
 }
 
 static
@@ -122,6 +107,7 @@ int connect_with_timeout(struct lttcomm_sock *sock)
        int ret, flags, connect_ret;
        struct timespec orig_time, cur_time;
        unsigned long diff_ms;
+       struct sockaddr_in sockaddr;
 
        ret = fcntl(sock->fd, F_GETFL, 0);
        if (ret == -1) {
@@ -143,10 +129,8 @@ int connect_with_timeout(struct lttcomm_sock *sock)
                return -1;
        }
 
-       connect_ret = connect(sock->fd,
-                       (const struct sockaddr *) ALIGNED_CONST_PTR(
-                                       sock->sockaddr.addr.sin),
-                       sizeof(sock->sockaddr.addr.sin));
+       sockaddr = sock->sockaddr.addr.sin;
+       connect_ret = connect(sock->fd, &sockaddr, sizeof(sockaddr));
        if (connect_ret == -1 && errno != EAGAIN && errno != EWOULDBLOCK &&
                        errno != EINPROGRESS) {
                goto error;
@@ -227,7 +211,6 @@ error:
 /*
  * Connect PF_INET socket.
  */
-LTTNG_HIDDEN
 int lttcomm_connect_inet_sock(struct lttcomm_sock *sock)
 {
        int ret, closeret;
@@ -257,7 +240,6 @@ error_connect:
  * Do an accept(2) on the sock and return the new lttcomm socket. The socket
  * MUST be bind(2) before.
  */
-LTTNG_HIDDEN
 struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock)
 {
        int new_fd;
@@ -321,7 +303,6 @@ error:
 /*
  * Make the socket listen using LTTNG_SESSIOND_COMM_MAX_LISTEN.
  */
-LTTNG_HIDDEN
 int lttcomm_listen_inet_sock(struct lttcomm_sock *sock, int backlog)
 {
        int ret;
@@ -352,7 +333,6 @@ end:
  *
  * Return the size of received data.
  */
-LTTNG_HIDDEN
 ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf,
                size_t len, int flags)
 {
@@ -381,7 +361,7 @@ ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf,
                        }
                        iov[0].iov_base += ret;
                        iov[0].iov_len -= ret;
-                       assert(ret <= len_last);
+                       LTTNG_ASSERT(ret <= len_last);
                }
        } while ((ret > 0 && ret < len_last) || (ret < 0 && errno == EINTR));
 
@@ -409,7 +389,6 @@ end:
  *
  * Return the size of sent data.
  */
-LTTNG_HIDDEN
 ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, const void *buf,
                size_t len, int flags)
 {
@@ -456,7 +435,6 @@ ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, const void *buf,
 /*
  * Shutdown cleanly and close.
  */
-LTTNG_HIDDEN
 int lttcomm_close_inet_sock(struct lttcomm_sock *sock)
 {
        int ret;
@@ -524,7 +502,6 @@ error:
        return val;
 }
 
-LTTNG_HIDDEN
 void lttcomm_inet_init(void)
 {
        unsigned long syn_retries, fin_timeout, syn_timeout, env;
This page took 0.026748 seconds and 4 git commands to generate.