当前位置: 首页>>代码示例>>C++>>正文


C++ SOCKET_ERROR函数代码示例

本文整理汇总了C++中SOCKET_ERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ SOCKET_ERROR函数的具体用法?C++ SOCKET_ERROR怎么用?C++ SOCKET_ERROR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SOCKET_ERROR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: throw

void
Comm::bind_gc () throw(socket_error)
{
  // create socket
  gc_sockn = ::socket(AF_INET, SOCK_DGRAM, 0);
  if (gc_sockn == -1) {
    stop();
    throw SOCKET_ERROR(errno);
  }

#ifdef COMM_LISTEN
  // set bind address parameters
  struct sockaddr_in bind_addr;
  bind_addr.sin_family = AF_INET;
  bind_addr.sin_port = htons(GAMECONTROLLER_PORT);
  bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);

  // bind socket to address
  if (::bind(gc_sockn, (const struct sockaddr*)&bind_addr,
        sizeof(bind_addr)) == -1) {
    stop();
    throw SOCKET_ERROR(errno);
  }
#endif

  // Set broadcast enabled on the socket
  int on = 1;
  setsockopt(gc_sockn, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));

//#ifdef COMM_LISTEN
  // Set socket to nonblocking io mode
  int flags = fcntl(gc_sockn, F_GETFL);
  fcntl(gc_sockn, F_SETFL, flags | O_NONBLOCK);
//#endif
}
开发者ID:I82Much,项目名称:nao-man,代码行数:35,代码来源:Comm.cpp

示例2: socket_server_impl

Variant socket_server_impl(
  const HostURL &hosturl,
  int flags, /* = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN */
  VRefParam errnum /* = null */,
  VRefParam errstr /* = null */
) {
  errnum = 0;
  errstr = empty_string();
  auto sock = create_new_socket(hosturl, errnum, errstr);
  if (!sock) {
    return false;
  }

  sockaddr_storage sa_storage;
  struct sockaddr *sa_ptr;
  size_t sa_size;
  if (!set_sockaddr(sa_storage, sock, hosturl.getHost().c_str(),
                    hosturl.getPort(), sa_ptr, sa_size)) {
    return false;
  }
  int yes = 1;
  setsockopt(sock->fd(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
  if ((flags & k_STREAM_SERVER_BIND) != 0 &&
      ::bind(sock->fd(), sa_ptr, sa_size) < 0) {
    SOCKET_ERROR(sock, "unable to bind to given address", errno);
    return false;
  }
  if ((flags & k_STREAM_SERVER_LISTEN) != 0 && listen(sock->fd(), 128) < 0) {
    SOCKET_ERROR(sock, "unable to listen on socket", errno);
    return false;
  }

  return Variant(std::move(sock));
}
开发者ID:191919,项目名称:hhvm,代码行数:34,代码来源:ext_sockets.cpp

示例3: f_socket_create_listen

Variant f_socket_create_listen(int port, int backlog /* = 128 */) {
  Util::HostEnt result;
  if (!Util::safe_gethostbyname("0.0.0.0", result)) {
    return false;
  }

  struct sockaddr_in la;
  memcpy((char *) &la.sin_addr, result.hostbuf.h_addr,
         result.hostbuf.h_length);
  la.sin_family = result.hostbuf.h_addrtype;
  la.sin_port = htons((unsigned short)port);

  Socket *sock = new Socket(socket(PF_INET, SOCK_STREAM, 0), PF_INET,
                            "0.0.0.0", port);
  Object ret(sock);
  if (!sock->valid()) {
    SOCKET_ERROR(sock, "unable to create listening socket", errno);
    return false;
  }

  if (::bind(sock->fd(), (struct sockaddr *)&la, sizeof(la)) < 0) {
    SOCKET_ERROR(sock, "unable to bind to given adress", errno);
    return false;
  }

  if (listen(sock->fd(), backlog) < 0) {
    SOCKET_ERROR(sock, "unable to listen on socket", errno);
    return false;
  }

  return ret;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:32,代码来源:ext_socket.cpp

示例4: f_socket_server

Variant f_socket_server(CStrRef hostname, int port /* = -1 */,
                        VRefParam errnum /* = null */,
                        VRefParam errstr /* = null */) {
  Object ret;
  Socket *sock = NULL;
  const char *name = hostname.data();
  if (!create_new_socket(name, port, errnum, errstr, ret, sock, 0.0)) {
    return false;
  }
  assert(ret.get() && sock);

  sockaddr_storage sa_storage;
  struct sockaddr *sa_ptr;
  size_t sa_size;
  if (!set_sockaddr(sa_storage, sock, name, port, sa_ptr, sa_size)) {
    return false;
  }
  if (::bind(sock->fd(), sa_ptr, sa_size) < 0) {
    SOCKET_ERROR(sock, "unable to bind to given adress", errno);
    return false;
  }
  if (listen(sock->fd(), 128) < 0) {
    SOCKET_ERROR(sock, "unable to listen on socket", errno);
    return false;
  }

  return ret;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:28,代码来源:ext_socket.cpp

示例5: HHVM_FUNCTION

Variant HHVM_FUNCTION(socket_create_listen,
                      int port,
                      int backlog /* = 128 */) {
  HostEnt result;
  if (!safe_gethostbyname("0.0.0.0", result)) {
    return false;
  }

  struct sockaddr_in la;
  memcpy((char *) &la.sin_addr, result.hostbuf.h_addr,
         result.hostbuf.h_length);
  la.sin_family = result.hostbuf.h_addrtype;
  la.sin_port = htons((unsigned short)port);

  auto sock = makeSmartPtr<Socket>(
    socket(PF_INET, SOCK_STREAM, 0), PF_INET, "0.0.0.0", port);

  if (!sock->valid()) {
    SOCKET_ERROR(sock, "unable to create listening socket", errno);
    return false;
  }

  if (::bind(sock->fd(), (struct sockaddr *)&la, sizeof(la)) < 0) {
    SOCKET_ERROR(sock, "unable to bind to given address", errno);
    return false;
  }

  if (listen(sock->fd(), backlog) < 0) {
    SOCKET_ERROR(sock, "unable to listen on socket", errno);
    return false;
  }

  return Variant(std::move(sock));
}
开发者ID:191919,项目名称:hhvm,代码行数:34,代码来源:ext_sockets.cpp

示例6: SSL_get_error

void C_SecureSocket::ssl_error(int P_returnCode) {
  
  int L_ret ;
  L_ret = SSL_get_error(m_ssl, P_returnCode) ;

  if (P_returnCode <= SSL_ERROR_WANT_CONNECT) {
    SOCKET_ERROR(0, m_ssl_error_string[L_ret]);
  } else {
     SOCKET_ERROR(0, "SSL error " << L_ret);
  }
}
开发者ID:Metaswitch,项目名称:clearwater-seagull,代码行数:11,代码来源:C_SecureSocket.cpp

示例7: f_socket_get_option

Variant f_socket_get_option(CObjRef socket, int level, int optname) {
  Socket *sock = socket.getTyped<Socket>();
  Array ret;
  socklen_t optlen;

  switch (optname) {
  case SO_LINGER:
    {
      struct linger linger_val;
      optlen = sizeof(linger_val);
      if (getsockopt(sock->fd(), level, optname, (char*)&linger_val,
                     &optlen) != 0) {
        SOCKET_ERROR(sock, "unable to retrieve socket option", errno);
        return false;
      }

      ret.set(s_l_onoff, linger_val.l_onoff);
      ret.set(s_l_linger, linger_val.l_linger);
    }
    break;

  case SO_RCVTIMEO:
  case SO_SNDTIMEO:
    {
      struct timeval tv;
      optlen = sizeof(tv);
      if (getsockopt(sock->fd(), level, optname, (char*)&tv, &optlen) != 0) {
        SOCKET_ERROR(sock, "unable to retrieve socket option", errno);
        return false;
      }
      ret.set(s_sec,  (int)tv.tv_sec);
      ret.set(s_usec, (int)tv.tv_usec);
    }
    break;

  default:
    {
      int other_val;
      optlen = sizeof(other_val);
      if (getsockopt(sock->fd(), level, optname, (char*)&other_val, &optlen)) {
        SOCKET_ERROR(sock, "unable to retrieve socket option", errno);
        return false;
      }
      return other_val;
    }
  }
  return ret;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:48,代码来源:ext_socket.cpp

示例8: create_new_socket

static bool create_new_socket(const char *&name, int port, Variant &errnum,
                              Variant &errstr, Object &ret, Socket *&sock,
                              double timeout) {
  int domain = AF_INET;
  int type = SOCK_STREAM;
  if (strncmp(name, "udp://", 6) == 0 || strncmp(name, "udg://", 6) == 0) {
    type = SOCK_DGRAM;
    name += 6;
  } else if (strncmp(name, "tcp://", 6) == 0) {
    name += 6;
  } else if (strncmp(name, "unix://", 7) == 0) {
    domain = AF_UNIX;
    name += 7;
  }

  sock = new Socket(socket(domain, type, 0), domain, name, port, timeout);
  ret = Object(sock);
  if (!sock->valid()) {
    SOCKET_ERROR(sock, "unable to create socket", errno);
    errnum = sock->getError();
    errstr = String(Util::safe_strerror(sock->getError()));
    return false;
  }
  return true;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:25,代码来源:ext_socket.cpp

示例9: SSL_new

int C_SecureSocketClient::_secure_mode() {
  int L_result, L_ret ;

  m_ssl = SSL_new(m_ssl_ctx);
  SSL_set_connect_state(m_ssl) ;
  
  if ((m_bio = BIO_new_socket(m_socket_id, BIO_CLOSE)) == NULL ) {
    SOCKET_ERROR(0, "Unable to create the BIO- client in New TLS connection");
  } 
 
  
  SSL_set_bio(m_ssl,m_bio,m_bio);
  
  L_result = SSL_connect(m_ssl) ;
  if ( L_result < 0 ) {
    if (SSL_get_error(m_ssl, L_result) == SSL_ERROR_WANT_READ) {
      m_state = E_SOCKET_STATE_INPROGESS ;
      L_ret = 0 ;
    } else {
      ssl_error(L_result);
      L_ret = -1 ;
    }
  } else {
    L_ret = 0 ;
  }
  return (L_ret);
  
}
开发者ID:Metaswitch,项目名称:clearwater-seagull,代码行数:28,代码来源:C_SecureSocket.cpp

示例10: create_new_socket

static SmartPtr<Socket> create_new_socket(
  const HostURL &hosturl,
  Variant &errnum,
  Variant &errstr
) {
  int domain = hosturl.isIPv6() ? AF_INET6 : AF_INET;
  int type = SOCK_STREAM;
  const std::string scheme = hosturl.getScheme();

  if (scheme == "udp" || scheme == "udg") {
    type = SOCK_DGRAM;
  } else if (scheme == "unix") {
    domain = AF_UNIX;
  }

  auto sock = makeSmartPtr<Socket>(
    socket(domain, type, 0),
    domain,
    hosturl.getHost().c_str(),
    hosturl.getPort()
  );

  if (!sock->valid()) {
    SOCKET_ERROR(sock, "unable to create socket", errno);
    errnum = sock->getError();
    errstr = HHVM_FN(socket_strerror)(sock->getError());
    sock.reset();
  }
  return sock;
}
开发者ID:191919,项目名称:hhvm,代码行数:30,代码来源:ext_sockets.cpp

示例11: php_set_inet6_addr

static bool php_set_inet6_addr(struct sockaddr_in6 *sin6, const char *address,
                               Socket *sock) {
  struct in6_addr tmp;
  struct addrinfo hints;
  struct addrinfo *addrinfo = NULL;

  if (inet_pton(AF_INET6, address, &tmp)) {
    memcpy(&(sin6->sin6_addr.s6_addr), &(tmp.s6_addr),
           sizeof(struct in6_addr));
  } else {
    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = PF_INET6;
    getaddrinfo(address, NULL, &hints, &addrinfo);
    if (!addrinfo) {
      SOCKET_ERROR(sock, "Host lookup failed", (-10000 - h_errno));
      return false;
    }
    if (addrinfo->ai_family != PF_INET6 ||
        addrinfo->ai_addrlen != sizeof(struct sockaddr_in6)) {
      raise_warning("Host lookup failed: Non AF_INET6 domain "
                      "returned on AF_INET6 socket");
      freeaddrinfo(addrinfo);
      return false;
    }

    memcpy(&(sin6->sin6_addr.s6_addr),
           ((struct sockaddr_in6*)(addrinfo->ai_addr))->sin6_addr.s6_addr,
           sizeof(struct in6_addr));
    freeaddrinfo(addrinfo);
  }

  return true;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:33,代码来源:ext_socket.cpp

示例12: f_socket_sendto

Variant f_socket_sendto(CObjRef socket, CStrRef buf, int len, int flags,
                        CStrRef addr, int port /* = 0 */) {
  Socket *sock = socket.getTyped<Socket>();
  if (len > buf.size()) {
    len = buf.size();
  }
  int retval;
  switch (sock->getType()) {
  case AF_UNIX:
    {
      struct sockaddr_un  s_un;
      memset(&s_un, 0, sizeof(s_un));
      s_un.sun_family = AF_UNIX;
      snprintf(s_un.sun_path, 108, "%s", addr.data());

      retval = sendto(sock->fd(), buf.data(), len, flags,
                      (struct sockaddr *)&s_un, SUN_LEN(&s_un));
    }
    break;
  case AF_INET:
    {
      struct sockaddr_in  sin;
      memset(&sin, 0, sizeof(sin));
      sin.sin_family = AF_INET;
      sin.sin_port = htons((unsigned short) port);
      if (!php_set_inet_addr(&sin, addr.c_str(), sock)) {
        return false;
      }

      retval = sendto(sock->fd(), buf.data(), len, flags,
                      (struct sockaddr *)&sin, sizeof(sin));
    }
    break;
  case AF_INET6:
    {
      struct sockaddr_in6  sin6;
      memset(&sin6, 0, sizeof(sin6));
      sin6.sin6_family = AF_INET6;
      sin6.sin6_port = htons((unsigned short) port);

      if (!php_set_inet6_addr(&sin6, addr.c_str(), sock)) {
        return false;
      }

      retval = sendto(sock->fd(), buf.data(), len, flags,
                      (struct sockaddr *)&sin6, sizeof(sin6));
    }
    break;
  default:
    raise_warning("Unsupported socket type %d", sock->getType());
    return false;
  }

  if (retval == -1) {
    SOCKET_ERROR(sock, "unable to write to socket", errno);
    return false;
  }

  return retval;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:60,代码来源:ext_socket.cpp

示例13: f_socket_listen

bool f_socket_listen(CObjRef socket, int backlog /* = 0 */) {
  Socket *sock = socket.getTyped<Socket>();
  if (listen(sock->fd(), backlog) != 0) {
    SOCKET_ERROR(sock, "unable to listen on socket", errno);
    return false;
  }
  return true;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:8,代码来源:ext_socket.cpp

示例14: f_socket_shutdown

bool f_socket_shutdown(CObjRef socket, int how /* = 0 */) {
  Socket *sock = socket.getTyped<Socket>();
  if (shutdown(sock->fd(), how) != 0) {
    SOCKET_ERROR(sock, "unable to shutdown socket", errno);
    return false;
  }
  return true;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:8,代码来源:ext_socket.cpp

示例15: f_socket_create

Variant f_socket_create(int domain, int type, int protocol) {
  check_socket_parameters(domain, type);
  int socketId = socket(domain, type, protocol);
  if (socketId == -1) {
    Socket dummySock; // for setting last socket error
    SOCKET_ERROR((&dummySock), "Unable to create socket", errno);
    return false;
  }
  Socket *sock = new Socket(socketId, domain);
  Object ret(sock);
  return ret;
}
开发者ID:hakanertug,项目名称:hiphop-php,代码行数:12,代码来源:ext_socket.cpp


注:本文中的SOCKET_ERROR函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。