當前位置: 首頁>>代碼示例>>C++>>正文


C++ FD_TO_SOCKET函數代碼示例

本文整理匯總了C++中FD_TO_SOCKET函數的典型用法代碼示例。如果您正苦於以下問題:C++ FD_TO_SOCKET函數的具體用法?C++ FD_TO_SOCKET怎麽用?C++ FD_TO_SOCKET使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了FD_TO_SOCKET函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: myAccept

static int
myAccept (int fd, struct sockaddr *addr, socklen_t *addrlen)
{
  SOCKET fh = SOCKET_ERROR;
  int new_fd;

  /* Parameters to system calls are not guaranteed to generate a SIGSEGV
     and for this reason we must touch them manually.  */
  _gst_grey_oop_range (addr, *addrlen);

#if defined SOCK_CLOEXEC && defined HAVE_ACCEPT4 && !defined __MSVCRT__
  if (have_sock_cloexec >= 0)
    {
      fh = accept4 (FD_TO_SOCKET (fd), addr, addrlen, SOCK_CLOEXEC);
      if (!check_have_sock_cloexec (fh, ENOSYS))
	return -1;
    }
#endif
  if (fh == SOCKET_ERROR)
    {
      fh = accept (FD_TO_SOCKET (fd), addr, addrlen);
      socket_set_cloexec (fh);
    }

  new_fd = (fh == SOCKET_ERROR ? -1 : SOCKET_TO_FD (fh));
  if (new_fd != SOCKET_ERROR)
    _gst_register_socket (new_fd, false);
  return new_fd;
}
開發者ID:NicolasPetton,項目名稱:smalltalk,代碼行數:29,代碼來源:sockets.c

示例2: _gl_close_fd_maybe_socket

static int
_gl_close_fd_maybe_socket (int fd)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  WSANETWORKEVENTS ev;

  ev.lNetworkEvents = 0xDEADBEEF;
  WSAEnumNetworkEvents (sock, NULL, &ev);
  if (ev.lNetworkEvents != 0xDEADBEEF)
    {
      /* FIXME: other applications, like squid, use an undocumented
	 _free_osfhnd free function.  But this is not enough: The 'osfile'
	 flags for fd also needs to be cleared, but it is hard to access it.
	 Instead, here we just close twice the file descriptor.  */
      if (closesocket (sock))
	{
	  set_winsock_errno ();
	  return -1;
	}
      else
	{
	  /* This call frees the file descriptor and does a
	     CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
	  _close (fd);
	  return 0;
	}
    }
  else
    return _close (fd);
}
開發者ID:BytEvil,項目名稱:screensavers.rsxs,代碼行數:30,代碼來源:close.c

示例3: ioctl_fd_maybe_socket

static int
ioctl_fd_maybe_socket (const struct fd_hook *remaining_list,
                       gl_ioctl_fn primary,
                       int fd, int request, void *arg)
{
  SOCKET sock;
  WSANETWORKEVENTS ev;

  /* Test whether fd refers to a socket.  */
  sock = FD_TO_SOCKET (fd);
  ev.lNetworkEvents = 0xDEADBEEF;
  WSAEnumNetworkEvents (sock, NULL, &ev);
  if (ev.lNetworkEvents != 0xDEADBEEF)
    {
      /* fd refers to a socket.  */
      if (ioctlsocket (sock, request, arg) < 0)
        {
          set_winsock_errno ();
          return -1;
        }
      else
        return 0;
    }
  else
    /* Some other type of file descriptor.  */
    return execute_ioctl_hooks (remaining_list, primary, fd, request, arg);
}
開發者ID:czchen,項目名稱:debian-libvirt,代碼行數:27,代碼來源:sockets.c

示例4: rpl_recvfrom

ssize_t
rpl_recvfrom (int fd, void *buf, size_t len, int flags, struct sockaddr *from,
              socklen_t *fromlen)
{
  SOCKET sock = FD_TO_SOCKET (fd);

  if (sock == INVALID_SOCKET)
    {
      errno = EBADF;
      return -1;
    }
  else
    {
      int frombufsize = (from != NULL ? *fromlen : 0);
      int r = recvfrom (sock, buf, len, flags, from, fromlen);

      if (r < 0)
        set_winsock_errno ();

      /* Winsock recvfrom() only returns a valid 'from' when the socket is
         connectionless.  POSIX gives a valid 'from' for all types of
         sockets.  */
      else if (from != NULL && *fromlen == frombufsize)
        rpl_getpeername (fd, from, fromlen);

      return r;
    }
}
開發者ID:cooljeanius,項目名稱:wget,代碼行數:28,代碼來源:recvfrom.c

示例5: rpl_setsockopt

int
rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  int r;

  if (sock == INVALID_SOCKET)
    {
      errno = EBADF;
      return -1;
    }
  else
    {
      if (level == SOL_SOCKET
          && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
        {
          const struct timeval *tv = optval;
          int milliseconds = tv->tv_sec * 1000 + tv->tv_usec / 1000;
          optval = &milliseconds;
          r = setsockopt (sock, level, optname, optval, sizeof (int));
        }
      else
        {
          r = setsockopt (sock, level, optname, optval, optlen);
        }

      if (r < 0)
        set_winsock_errno ();

      return r;
    }
}
開發者ID:Prelude-SIEM,項目名稱:libprelude,代碼行數:32,代碼來源:setsockopt.c

示例6: rpl_connect

int
rpl_connect (int fd, const struct sockaddr *sockaddr, socklen_t len)
{
  SOCKET sock = FD_TO_SOCKET (fd);

  if (sock == INVALID_SOCKET)
    {
      errno = EBADF;
      return -1;
    }
  else
    {
      int r = connect (sock, sockaddr, len);
      if (r < 0)
        {
          /* EINPROGRESS is not returned by WinSock 2.0; for backwards
             compatibility, connect(2) uses EWOULDBLOCK.  */
          if (WSAGetLastError () == WSAEWOULDBLOCK)
            WSASetLastError (WSAEINPROGRESS);

          set_winsock_errno ();
        }

      return r;
    }
}
開發者ID:GostCrypt,項目名稱:GnuTLS,代碼行數:26,代碼來源:connect.c

示例7: myConnect

/* Same as connect, but forces the socket to be in non-blocking mode */
static int
myConnect (int fd, struct sockaddr *sockaddr, int len)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  int rc;

#ifdef __MSVCRT__
  unsigned long iMode = 1;
  ioctlsocket (sock, FIONBIO, &iMode);

#elif defined F_GETFL
#ifndef O_NONBLOCK             
#warning Non-blocking I/O could not be enabled
#else
  int oldflags = fcntl (sock, F_GETFL, NULL);
  if (!(oldflags & O_NONBLOCK))
    fcntl (sock, F_SETFL, oldflags | O_NONBLOCK);
#endif
#endif
  
  fix_sockaddr (sockaddr);
  rc = connect (sock, sockaddr, len);
  if (rc == 0 || is_socket_error (EINPROGRESS) || is_socket_error (EWOULDBLOCK))
    return 0;
  else
    return -1;
}
開發者ID:NicolasPetton,項目名稱:smalltalk,代碼行數:28,代碼來源:sockets.c

示例8: ssl_connect_wget

bool
ssl_connect_wget (int fd, const char *hostname)
{
  SSL *conn;
  struct scwt_context scwt_ctx;
  struct openssl_transport_context *ctx;

  DEBUGP (("Initiating SSL handshake.\n"));

  assert (ssl_ctx != NULL);
  conn = SSL_new (ssl_ctx);
  if (!conn)
    goto error;
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
  /* If the SSL library was build with support for ServerNameIndication
     then use it whenever we have a hostname.  If not, don't, ever. */
  if (! is_valid_ip_address (hostname))
    {
      if (! SSL_set_tlsext_host_name (conn, hostname))
        {
          DEBUGP (("Failed to set TLS server-name indication."));
          goto error;
        }
    }
#endif

#ifndef FD_TO_SOCKET
# define FD_TO_SOCKET(X) (X)
#endif
  if (!SSL_set_fd (conn, FD_TO_SOCKET (fd)))
    goto error;
  SSL_set_connect_state (conn);

  scwt_ctx.ssl = conn;
  if (run_with_timeout(opt.read_timeout, ssl_connect_with_timeout_callback,
                       &scwt_ctx)) {
    DEBUGP (("SSL handshake timed out.\n"));
    goto timeout;
  }
  if (scwt_ctx.result <= 0 || conn->state != SSL_ST_OK)
    goto error;

  ctx = xnew0 (struct openssl_transport_context);
  ctx->conn = conn;

  /* Register FD with Wget's transport layer, i.e. arrange that our
     functions are used for reading, writing, and polling.  */
  fd_register_transport (fd, &openssl_transport, ctx);
  DEBUGP (("Handshake successful; connected socket %d to SSL handle 0x%0*lx\n",
           fd, PTR_FORMAT (conn)));
  return true;

 error:
  DEBUGP (("SSL handshake failed.\n"));
  print_errors ();
 timeout:
  if (conn)
    SSL_free (conn);
  return false;
}
開發者ID:giuseppe,項目名稱:wget,代碼行數:60,代碼來源:openssl.c

示例9: mySendto

static int
mySendto (int fd, const char *buf, int len, int flags,
	  struct sockaddr *to, int tolen)
{
  fix_sockaddr (to);
  return sendto (FD_TO_SOCKET (fd), buf, len, flags, to, tolen);
}
開發者ID:NicolasPetton,項目名稱:smalltalk,代碼行數:7,代碼來源:sockets.c

示例10: _gst_send

ssize_t
_gst_send (int fd,
	   PTR buffer,
	   size_t size,
	   int flags)
{
#ifdef HAVE_SOCKETS
  ssize_t result;
  int save_errno = errno;

  for (;;)
    {
      result = send (FD_TO_SOCKET (fd), buffer, size, flags);
      if (is_socket_error (EFAULT))
        abort ();

      if (is_socket_error (EINTR))
	clear_socket_error ();
      else
	break;
    }

  if (errno == EINTR)
    errno = save_errno;

  return result;
#else
  errno = ENOSYS;
  return -1;
#endif
}
開發者ID:MrVertinskis,項目名稱:smalltalk,代碼行數:31,代碼來源:files.c

示例11: myListen

static int
myListen (int fd, int backlog)
{
  int r = listen (FD_TO_SOCKET (fd), backlog);
  if (r != SOCKET_ERROR)
    _gst_register_socket (fd, true);
  return r;
}
開發者ID:NicolasPetton,項目名稱:smalltalk,代碼行數:8,代碼來源:sockets.c

示例12: ssl_connect_wget

bool
ssl_connect_wget (int fd)
{
  static const int cert_type_priority[] = {
    GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0
  };
  struct wgnutls_transport_context *ctx;
  gnutls_session session;
  int err;
  int allowed_protocols[4] = {0, 0, 0, 0};
  gnutls_init (&session, GNUTLS_CLIENT);
  gnutls_set_default_priority (session);
  gnutls_certificate_type_set_priority (session, cert_type_priority);
  gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, credentials);
#ifndef FD_TO_SOCKET
# define FD_TO_SOCKET(X) (X)
#endif
  gnutls_transport_set_ptr (session, (gnutls_transport_ptr) FD_TO_SOCKET (fd));

  err = 0;
  switch (opt.secure_protocol)
    {
    case secure_protocol_auto:
      break;
    case secure_protocol_sslv2:
    case secure_protocol_sslv3:
      allowed_protocols[0] = GNUTLS_SSL3;
      err = gnutls_protocol_set_priority (session, allowed_protocols);
      break;
    case secure_protocol_tlsv1:
      allowed_protocols[0] = GNUTLS_TLS1_0;
      allowed_protocols[1] = GNUTLS_TLS1_1;
      allowed_protocols[2] = GNUTLS_TLS1_2;
      err = gnutls_protocol_set_priority (session, allowed_protocols);
      break;
    default:
      abort ();
    }
  if (err < 0)
    {
      logprintf (LOG_NOTQUIET, "GnuTLS: %s\n", gnutls_strerror (err));
      gnutls_deinit (session);
      return false;
    }

  err = gnutls_handshake (session);
  if (err < 0)
    {
      logprintf (LOG_NOTQUIET, "GnuTLS: %s\n", gnutls_strerror (err));
      gnutls_deinit (session);
      return false;
    }

  ctx = xnew0 (struct wgnutls_transport_context);
  ctx->session = session;
  fd_register_transport (fd, &wgnutls_transport, ctx);
  return true;
}
開發者ID:db48x,項目名稱:wget-warc,代碼行數:58,代碼來源:gnutls.c

示例13: myGetsockopt

static int
myGetsockopt (int fd, int level, int optname, char *optval, socklen_t *optlen)
{
  /* Parameters to system calls are not guaranteed to generate a SIGSEGV
     and for this reason we must touch them manually.  */
  _gst_grey_oop_range (optval, *optlen);

  return getsockopt (FD_TO_SOCKET (fd), level, optname, optval, optlen);
}
開發者ID:NicolasPetton,項目名稱:smalltalk,代碼行數:9,代碼來源:sockets.c

示例14: myGetsockname

static int
myGetsockname (int fd, struct sockaddr *addr, socklen_t *addrlen)
{
  /* Parameters to system calls are not guaranteed to generate a SIGSEGV
     and for this reason we must touch them manually.  */
  _gst_grey_oop_range (addr, *addrlen);

  return getsockname (FD_TO_SOCKET (fd), addr, addrlen);
}
開發者ID:NicolasPetton,項目名稱:smalltalk,代碼行數:9,代碼來源:sockets.c

示例15: rpl_listen

int
rpl_listen (int fd, int backlog)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  int r = listen (sock, backlog);
  if (r < 0)
    set_winsock_errno ();

  return r;
}
開發者ID:Chronic-Dev,項目名稱:gnutls,代碼行數:10,代碼來源:listen.c


注:本文中的FD_TO_SOCKET函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。