ext/iodine/fio.c
/* PUBLIC API: opens a server or client socket */
PUBLIC API: opens a server or client socket
PUBLIC API : opens a server or client socket
intptr_t fio_socket(const char *address, const char *port, uint8_t server) {
  intptr_t uuid;
  if (port) {
    char *pos = (char *)port;
    int64_t n = fio_atol(&pos);
    if (*pos) {
      FIO_LOG_ERROR("(fio_socket) port %s is not a number.", port);
      errno = EINVAL;
      return -1;
    }
    if (n <= 0) {
      if (n < -1)
        FIO_LOG_WARNING("(fio_socket) negative port number %s is ignored.",
                        port);
      port = NULL;
    }
  }
  if (!address && !port) {
    FIO_LOG_ERROR("(fio_socket) both address and port are missing or invalid.");
    errno = EINVAL;
    return -1;
  }
  if (!port) {
    do {
      errno = 0;
      uuid = fio_unix_socket(address, server);
    } while (errno == EINTR);
  } else {
    do {
      errno = 0;
      uuid = fio_tcp_socket(address, port, server);
    } while (errno == EINTR);
  }
  return uuid;
}
intptr_t fio_socket ( const char * address , const char * port , uint8_t server ) { intptr_t uuid ; if ( port ) { char * pos = ( char * ) port ; int64_t n = fio_atol ( & pos ) ; if ( * pos ) { FIO_LOG_ERROR ( " " , port ) ; errno = EINVAL ; return -1 ; } if ( n <= 0 ) { if ( n < -1 ) FIO_LOG_WARNING ( " " , port ) ; port = NULL ; } } if ( ! address && ! port ) { FIO_LOG_ERROR ( " " ) ; errno = EINVAL ; return -1 ; } if ( ! port ) { do { errno = 0 ; uuid = fio_unix_socket ( address , server ) ; } while ( errno == EINTR ) ; } else { do { errno = 0 ; uuid = fio_tcp_socket ( address , port , server ) ; } while ( errno == EINTR ) ; } return uuid ; }
PUBLIC API: opens a server or client socket
PUBLIC API : opens a server or client socket
/* make sure port is only numerical */ /* a negative port number will revert to a Unix socket. */