• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ FD_TO_SOCKET函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了FD_TO_SOCKET函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: rpl_send

ssize_t
rpl_send (int fd, const void *buf, size_t len, int flags)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  int r = send (sock, buf, len, flags);
  if (r < 0)
    set_winsock_errno ();

  return r;
}
开发者ID:Airswoop1,项目名称:sample_app,代码行数:10,代码来源:send.c


示例17: rpl_getpeername

int
rpl_getpeername (int fd, struct sockaddr *addr, socklen_t *addrlen)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  int r = getpeername (sock, addr, addrlen);
  if (r < 0)
    set_winsock_errno ();

  return r;
}
开发者ID:djmitche,项目名称:gnulib,代码行数:10,代码来源:getpeername.c


示例18: rpl_shutdown

int
rpl_shutdown (int fd, int how)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  int r = shutdown (sock, how);
  if (r < 0)
    set_winsock_errno ();

  return r;
}
开发者ID:DesmondWu,项目名称:gnulib,代码行数:10,代码来源:shutdown.c


示例19: rpl_bind

int
rpl_bind (int fd, struct sockaddr *sockaddr, int len)
{
  SOCKET sock = FD_TO_SOCKET (fd);
  int r = bind (sock, sockaddr, len);
  if (r < 0)
    set_winsock_errno ();

  return r;
}
开发者ID:Distrotech,项目名称:libprelude,代码行数:10,代码来源:bind.c


示例20: rpl_getsockopt

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

  if (sock == INVALID_SOCKET)
    {
      errno = EBADF;
      return -1;
    }
  else
    {
      int r;

      if (level == SOL_SOCKET
          && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
        {
          int milliseconds;
          int milliseconds_len = sizeof (int);
          struct timeval tv;
          size_t n;

          r = getsockopt (sock, level, optname, (char *) &milliseconds,
                          &milliseconds_len);
          tv.tv_sec = milliseconds / 1000;
          tv.tv_usec = (milliseconds - 1000 * tv.tv_sec) * 1000;
          n = sizeof (struct timeval);
          if (n > *optlen)
            n = *optlen;
          memcpy (optval, &tv, n);
          *optlen = n;
        }
      else
        {
          r = getsockopt (sock, level, optname, optval, optlen);
        }

      if (r < 0)
        set_winsock_errno ();

      return r;
    }
}
开发者ID:FaSan,项目名称:Mingle,代码行数:43,代码来源:getsockopt.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ FD_ZERO函数代码示例发布时间:2022-05-30
下一篇:
C++ FD_SET函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap