Пример #1
0
static int
fq_socket_connect(fq_conn_s *conn_s) {
  int fd, rv, on = 1;
  /* re-resolve if we've not done so quite recently */
  if(conn_s->last_resolve == 0 ||
     (fq_gethrtime() - conn_s->last_resolve) > MAX_RESOLVE_CACHE) {
    if(fq_resolve_endpoint(conn_s) < 0) {
      return -1;
    }
  }
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if(fd == -1) return -1;
  rv = connect(fd, (struct sockaddr *)&conn_s->remote,
               sizeof(conn_s->remote));
  if(rv == -1) {
    snprintf(conn_s->error, sizeof(conn_s->error),
             "socket: %s", strerror(errno));
    CONNERR_S(conn_s);
    close(fd);
    return -1;
  }
  /* If this fails, we ignore it */
  (void)setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
  return fd;
}
Пример #2
0
static int
fq_socket_connect(fq_conn_s *conn_s) {
  int fd, rv, on = 1;
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if(fd == -1) return -1;
  rv = connect(fd, (struct sockaddr *)&conn_s->remote,
               sizeof(conn_s->remote));
  if(rv == -1) {
    snprintf(conn_s->error, sizeof(conn_s->error),
             "socket: %s", strerror(errno));
    CONNERR_S(conn_s);
    close(fd);
    return -1;
  }
  setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
  return fd;
}