Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1170803a authored by Erwin Jansen's avatar Erwin Jansen
Browse files

Fix small socket config issues.

There were a few incorrect socket configurations issues. These
configuration issues could result in delays during the closing of
sockets when no connection was established.

Test: cert/run --clean
Change-Id: I53b2b1942aa67cf9fac78fc4343afd6c38507ac6
parent 74f8c003
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -38,7 +38,11 @@ namespace net {
PosixAsyncSocket::PosixAsyncSocket(int fd, AsyncManager* am)
    : fd_(fd), am_(am), watching_(false) {
  int flags = fcntl(fd, F_GETFL);
  fcntl(fd, F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC);
  fcntl(fd, F_SETFL, flags | O_NONBLOCK);

  flags = fcntl(fd, F_GETFD);
  fcntl(fd, F_SETFD, flags | O_CLOEXEC);

#ifdef SO_NOSIGPIPE
  // Disable SIGPIPE generation on Darwin.
  // When writing to a broken pipe, send() will return -1 and
+8 −7
Original line number Diff line number Diff line
@@ -14,14 +14,14 @@
// limitations under the License.
#include "net/posix/posix_async_socket_connector.h"

#include <arpa/inet.h>   // for inet_addr, inet_ntoa
#include <errno.h>       // for errno, EAGAIN, EINPROGRESS
#include <fcntl.h>       // for fcntl, F_GETFL, F_SETFL
#include <netdb.h>       // for gethostbyname
#include <netinet/in.h>  // for sockaddr_in, INADDR_ANY
#include <netdb.h>       // for gethostbyname, addrinfo
#include <netinet/in.h>  // for sockaddr_in, in_addr
#include <poll.h>        // for poll, POLLHUP, POLLIN, POL...
#include <string.h>      // for strerror, memset, NULL
#include <sys/socket.h>  // for connect, getsockopt, socket
#include <unistd.h>      // for close
#include <string.h>      // for strerror, NULL
#include <sys/socket.h>  // for connect, getpeername, gets...
#include <type_traits>   // for remove_extent_t

#include "net/posix/posix_async_socket.h"  // for PosixAsyncSocket
#include "os/log.h"                        // for LOG_INFO
@@ -57,9 +57,10 @@ PosixAsyncSocketConnector::ConnectToRemoteServer(
    return pas;
  }

  struct in_addr** addr_list = (struct in_addr**)host->h_addr_list;
  struct sockaddr_in serv_addr {};
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*addr_list[0]));
  serv_addr.sin_port = htons(port);

  int result =