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

C++ sock_errno函数代码示例

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

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



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

示例1: check_connection_completion

int
check_connection_completion(int fd)
{
    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
    struct pollfd pfd;
    int retval;

    pfd.fd = fd;
    pfd.events = POLLOUT;

#ifndef _WIN32
    do {
        retval = poll(&pfd, 1, 0);
    } while (retval < 0 && errno == EINTR);
#else
    retval = WSAPoll(&pfd, 1, 0);
#endif
    if (retval == 1) {
        if (pfd.revents & POLLERR) {
            ssize_t n = send(fd, "", 1, 0);
            if (n < 0) {
                return sock_errno();
            } else {
                VLOG_ERR_RL(&rl, "poll return POLLERR but send succeeded");
                return EPROTO;
            }
        }
        return 0;
    } else if (retval < 0) {
        VLOG_ERR_RL(&rl, "poll: %s", sock_strerror(sock_errno()));
        return errno;
    } else {
        return EAGAIN;
    }
}
开发者ID:AlexanderFroemmgen,项目名称:ovs,代码行数:35,代码来源:socket-util.c


示例2: acceptex_thread

void acceptex_thread()
{
      long sock_accex, recvd = 0;
      long locallen,clilen;
      char *Outbuff;
      int alloc = 1024;
      struct sockaddr_in local;
      struct sockaddr_in cli_addr;
      locallen = sizeof(local);
      clilen = sizeof(cli_addr);

      Outbuff = (char*) malloc( alloc );
      if (Outbuff == NULL) {
        printf("malloc error");
        total_threads++;
        exit(0);
      }
Begin:
      sock_accex = -1;
      recvd = accept_and_recv(sockfd,&sock_accex,(struct sockaddr *)&cli_addr, &clilen,(struct sockaddr *)&local,&locallen,Outbuff,alloc);
      if(recvd < 0)
        {
           printf("error in acceptex recv= %d\n",sock_errno());
           total_threads++;
           goto Begin;
           locallen = sizeof(local);
           clilen = sizeof(cli_addr);
           alloc =1024;
           recvd = accept_and_recv(sockfd,&sock_accex,(struct sockaddr *)&cli_addr, &clilen,(struct sockaddr *)&local,&locallen,Outbuff,alloc);
              if(recvd < 0)
                {
                   printf("error in acceptex recv= %d\n",sock_errno());
        }
        else
        {
              locallen = sizeof(local);
              clilen = sizeof(cli_addr);
              alloc =1024;
              recvd = accept_and_recv(sockfd,&sock_accex,(struct sockaddr *)&cli_addr, &clilen,(struct sockaddr *)&local,&locallen,Outbuff,alloc);
              if(recvd < 0)
                   printf("error in acceptex recv= %d\n",sock_errno());
        }
}

       printf(" Local addr :%x, Local_addr_len :%d\n",local.sin_addr.s_addr,locallen);
       printf(" Bytes recieved with acceptex :%d\n",recvd);
       printf(" Msg recvd with acceptex :%s\n",Outbuff);
       printf(" Recv socket Id :%d\n",sock_accex);
       printf("Before soclose\n");
       soclose(sock_accex);
       printf("after soclose\n");
       total_threads++;
       return ;
}
开发者ID:MbqIIB,项目名称:DEV-SAMPLES-IBM_Dev_Toolkit_Samples,代码行数:54,代码来源:accept.c


示例3: packet_socket

static int packet_socket(struct sock *sk, int type, int proto)
{
	struct packet_priv *priv = rte_malloc(NULL, sizeof(*sk->priv), 0);

	if (!priv)
		return sock_errno(sk, ENOMEM);

	priv->type = type;

	sk->priv = priv;

	return sock_errno(sk, 0);
}
开发者ID:labeneator,项目名称:accel-ppp,代码行数:13,代码来源:af_packet.c


示例4: check_connection_completion

int
check_connection_completion(int fd)
{
    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
    struct pollfd pfd;
    int retval;

    pfd.fd = fd;
    pfd.events = POLLOUT;

#ifndef _WIN32
    do {
        retval = poll(&pfd, 1, 0);
    } while (retval < 0 && errno == EINTR);
#else
    fd_set wrset, exset;
    FD_ZERO(&wrset);
    FD_ZERO(&exset);
    FD_SET(fd, &exset);
    FD_SET(fd, &wrset);
    pfd.revents = 0;
    struct timeval tv = { 0, 0 };
    /* WSAPoll is broken on Windows, instead do a select */
    retval = select(0, NULL, &wrset, &exset, &tv);
    if (retval == 1) {
        if (FD_ISSET(fd, &wrset)) {
            pfd.revents |= pfd.events;
        }
        if (FD_ISSET(fd, &exset)) {
            pfd.revents |= POLLERR;
        }
    }
#endif
    if (retval == 1) {
        if (pfd.revents & POLLERR) {
            ssize_t n = send(fd, "", 1, 0);
            if (n < 0) {
                return sock_errno();
            } else {
                VLOG_ERR_RL(&rl, "poll return POLLERR but send succeeded");
                return EPROTO;
            }
        }
        return 0;
    } else if (retval < 0) {
        VLOG_ERR_RL(&rl, "poll: %s", sock_strerror(sock_errno()));
        return errno;
    } else {
        return EAGAIN;
    }
}
开发者ID:aserdean,项目名称:ovs,代码行数:51,代码来源:socket-util.c


示例5: APR_DECLARE

APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock, 
                                           const struct iovec *vec, 
                                           apr_int32_t nvec, apr_size_t *len)
{
    apr_status_t rv;
    struct iovec *tmpvec;
    int fds, err = 0;
    int nv_tosend, total = 0;

    /* Make sure writev() only gets fed 64k at a time */
    for ( nv_tosend = 0; nv_tosend < nvec && total + vec[nv_tosend].iov_len < 65536; nv_tosend++ ) {
        total += vec[nv_tosend].iov_len;
    }

    tmpvec = alloca(sizeof(struct iovec) * nv_tosend);
    memcpy(tmpvec, vec, sizeof(struct iovec) * nv_tosend);

    do {
        if (!sock->nonblock || err == SOCEWOULDBLOCK) {
            fds = sock->socketdes;
            rv = select(&fds, 0, 1, 0, sock->timeout >= 0 ? sock->timeout/1000 : -1);

            if (rv != 1) {
                *len = 0;
                err = sock_errno();

                if (rv == 0)
                    return APR_TIMEUP;

                if (err == SOCEINTR)
                    continue;

                return APR_OS2_STATUS(err);
            }
        }

        rv = writev(sock->socketdes, tmpvec, nv_tosend);
        err = rv < 0 ? sock_errno() : 0;
    } while (err == SOCEINTR || err == SOCEWOULDBLOCK);

    if (err) {
        *len = 0;
        return APR_OS2_STATUS(err);
    }

    *len = rv;
    return APR_SUCCESS;
}
开发者ID:Ga-vin,项目名称:apache,代码行数:48,代码来源:sendrecv.c


示例6: tlso_bio_read

static int
tlso_bio_read( BIO *b, char *buf, int len )
{
	struct tls_data		*p;
	int			ret;
		
	if ( buf == NULL || len <= 0 ) return 0;

	p = (struct tls_data *)BIO_get_data(b);

	if ( p == NULL || p->sbiod == NULL ) {
		return 0;
	}

	ret = LBER_SBIOD_READ_NEXT( p->sbiod, buf, len );

	BIO_clear_retry_flags( b );
	if ( ret < 0 ) {
		int err = sock_errno();
		if ( err == EAGAIN || err == EWOULDBLOCK ) {
			BIO_set_retry_read( b );
		}
	}

	return ret;
}
开发者ID:osstech-jp,项目名称:openldap,代码行数:26,代码来源:tls_o.c


示例7: ldap_int_flush_request

/* protected by conn_mutex */
int
ldap_int_flush_request(
	LDAP *ld,
	LDAPRequest *lr )
{
	LDAPConn *lc = lr->lr_conn;

	LDAP_ASSERT_MUTEX_OWNER( &ld->ld_conn_mutex );
	if ( ber_flush2( lc->lconn_sb, lr->lr_ber, LBER_FLUSH_FREE_NEVER ) != 0 ) {
		if ( sock_errno() == EAGAIN ) {
			/* need to continue write later */
			lr->lr_status = LDAP_REQST_WRITING;
			ldap_mark_select_write( ld, lc->lconn_sb );
			ld->ld_errno = LDAP_BUSY;
			return -2;
		} else {
			ld->ld_errno = LDAP_SERVER_DOWN;
			ldap_free_request( ld, lr );
			ldap_free_connection( ld, lc, 0, 0 );
			return( -1 );
		}
	} else {
		if ( lr->lr_parent == NULL ) {
			lr->lr_ber->ber_end = lr->lr_ber->ber_ptr;
			lr->lr_ber->ber_ptr = lr->lr_ber->ber_buf;
		}
		lr->lr_status = LDAP_REQST_INPROGRESS;

		/* sent -- waiting for a response */
		ldap_mark_select_read( ld, lc->lconn_sb );
		ldap_clear_select_write( ld, lc->lconn_sb );
	}
	return 0;
}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:35,代码来源:request.c


示例8: xstrerror_a

/*
 * xstrerror() - sock_errno/strerror-like wrapper
 */
const char *
xstrerror_a(void)

{   int ierr;
    ierr = sock_errno();
    return xbstrerror_i(ierr);
}
开发者ID:ErisBlastar,项目名称:osfree,代码行数:10,代码来源:F_errors.cpp


示例9: new_tcp_stream

static int
new_tcp_stream(const char *name, int fd, int connect_status,
               struct stream **streamp)
{
    struct sockaddr_storage local;
    socklen_t local_len = sizeof local;
    int on = 1;
    int retval;

    /* Get the local IP and port information */
    retval = getsockname(fd, (struct sockaddr *) &local, &local_len);
    if (retval) {
        memset(&local, 0, sizeof local);
    }

    retval = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof on);
    if (retval) {
        int error = sock_errno();
        VLOG_ERR("%s: setsockopt(TCP_NODELAY): %s",
                 name, sock_strerror(error));
        close(fd);
        return error;
    }

    return new_fd_stream(name, fd, connect_status, streamp);
}
开发者ID:florincoras,项目名称:openvswitch,代码行数:26,代码来源:stream-tcp.c


示例10: packet_bind

static int packet_bind(struct sock *sk, const struct sockaddr *a, socklen_t addrlen)
{
	struct sockaddr_ll *addr = (struct sockaddr_ll *)a;
	struct net_device *dev = NULL;

	if (addrlen != sizeof(*addr))
		return sock_errno(sk, EINVAL);

	if (addr->sll_ifindex) {
		dev = netdev_get_by_index(addr->sll_ifindex);
		if (!dev)
			return sock_errno(sk, ENODEV);
	}

	return sock_errno(sk, 0);
}
开发者ID:labeneator,项目名称:accel-ppp,代码行数:16,代码来源:af_packet.c


示例11: set_dscp

/* Sets the DSCP value of socket 'fd' to 'dscp', which must be 63 or less.
 * 'family' must indicate the socket's address family (AF_INET or AF_INET6, to
 * do anything useful). */
int
set_dscp(int fd, int family, uint8_t dscp)
{
    int retval;
    int val;

#ifdef _WIN32
    /* XXX: Consider using QoS2 APIs for Windows to set dscp. */
    return 0;
#endif

    if (dscp > 63) {
        return EINVAL;
    }
    val = dscp << 2;

    switch (family) {
    case AF_INET:
        retval = setsockopt(fd, IPPROTO_IP, IP_TOS, &val, sizeof val);
        break;

    case AF_INET6:
        retval = setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &val, sizeof val);
        break;

    default:
        return ENOPROTOOPT;
    }

    return retval ? sock_errno() : 0;
}
开发者ID:AlexanderFroemmgen,项目名称:ovs,代码行数:34,代码来源:socket-util.c


示例12: return

/* Converts a string containing a valid internet address using
   dotted-decimal notation or host name into an internet address
   number typed as an unsigned long value.  A -1 value
   indicates an error. */
u_long XIOsocket::get_address(const char* hostname)
{
  u_long address;
  struct hostent* entry;

  if (!hostname)
  { errno = HBASEERR + HOST_NOT_FOUND;
    return (u_long)-1L;
  }

  if ((address = inet_addr((char*)hostname)) == (u_long)-1L)
  { if ((entry = gethostbyname((char*)hostname)) != NULL)
    { memcpy( &address, entry->h_addr, sizeof( address ));
    } else
    {
      #ifdef NETDB_INTERNAL
      if (h_errno == NETDB_INTERNAL)
        errno = sock_errno();
      else
      #endif
        errno = h_errno + HBASEERR;
    }
  }

  return address;
}
开发者ID:OS2World,项目名称:MM-SOUND-PM123,代码行数:30,代码来源:xio_socket.cpp


示例13: tlso_bio_write

static int
tlso_bio_write( BIO *b, const char *buf, int len )
{
	struct tls_data		*p;
	int			ret;
	
	if ( buf == NULL || len <= 0 ) return 0;
	
	p = (struct tls_data *)b->ptr;

	if ( p == NULL || p->sbiod == NULL ) {
		return 0;
	}

	ret = LBER_SBIOD_WRITE_NEXT( p->sbiod, (char *)buf, len );

	BIO_clear_retry_flags( b );
	if ( ret < 0 ) {
		int err = sock_errno();
		if ( err == EAGAIN || err == EWOULDBLOCK ) {
			BIO_set_retry_write( b );
		}
	}

	return ret;
}
开发者ID:cptaffe,项目名称:openldap,代码行数:26,代码来源:tls_o.c


示例14: sb_debug_write

static ber_slen_t
sb_debug_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
{
	ber_slen_t		ret;
	char ebuf[128];

	ret = LBER_SBIOD_WRITE_NEXT( sbiod, buf, len );
	if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS) {
		int err = sock_errno();
		if ( ret < 0 ) {
			ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
				"%swrite: want=%ld error=%s\n",
				(char *)sbiod->sbiod_pvt, (long)len,
				AC_STRERROR_R( err, ebuf, sizeof ebuf ) );
		} else {
			ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
				"%swrite: want=%ld, written=%ld\n",
				(char *)sbiod->sbiod_pvt, (long)len, (long)ret );
			ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
				(const char *)buf, ret );
		}
		sock_errset(err);
	}

	return ret;
}
开发者ID:ystk,项目名称:debian-openldap,代码行数:26,代码来源:sockbuf.c


示例15: set_nonblocking

/* Sets 'fd' to non-blocking mode.  Returns 0 if successful, otherwise a
 * positive errno value. */
int
set_nonblocking(int fd)
{
#ifndef _WIN32
    int flags = fcntl(fd, F_GETFL, 0);
    if (flags != -1) {
        if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) != -1) {
            return 0;
        } else {
            VLOG_ERR("fcntl(F_SETFL) failed: %s", ovs_strerror(errno));
            return errno;
        }
    } else {
        VLOG_ERR("fcntl(F_GETFL) failed: %s", ovs_strerror(errno));
        return errno;
    }
#else
    unsigned long arg = 1;
    if (ioctlsocket(fd, FIONBIO, &arg)) {
        int error = sock_errno();
        VLOG_ERR("set_nonblocking failed: %s", sock_strerror(error));
        return error;
    }
    return 0;
#endif
}
开发者ID:AlexanderFroemmgen,项目名称:ovs,代码行数:28,代码来源:socket-util.c


示例16: ber_int_sb_write

ber_slen_t
ber_int_sb_write( Sockbuf *sb, void *buf, ber_len_t len )
{
    ber_slen_t		ret;

    assert( buf != NULL );
    assert( sb != NULL);
    assert( sb->sb_iod != NULL );
    assert( SOCKBUF_VALID( sb ) );

    for (;;) {
        ret = sb->sb_iod->sbiod_io->sbi_write( sb->sb_iod, buf, len );

#ifdef EINTR
        if ( ret < 0 )
        {
#ifdef HAVE_WINSOCK     // on Windows, errno is NOT set by send call automatically.
            if ( (errno = sock_errno()) == WSAEINTR)
            {
                errno = EINTR;
            }
#endif
            if( errno == EINTR )  continue;
        }
#endif

        break;
    }

    return ret;
}
开发者ID:saberlilydian,项目名称:lightwave,代码行数:31,代码来源:sockbuf.c


示例17: character

/* Receives bytes on a socket up to the first new-line character (\n)
   or until the number of bytes received is equal to n-1, whichever
   comes first. Stores the result in string and adds a null
   character (\0) to the end of the string. If n is equal to 1, the
   string is empty. Returns a pointer to the string buffer if successful.
   A NULL return value indicates an error or that the connection is
   closed.*/
char* XIOsocket::gets(char* buffer, unsigned int size)
{
  unsigned int done = 0;
  char* p  = buffer;
  DEBUGLOG(("XIOsocket(%p{%d})::gets(%p, %d)\n", this, s_handle, buffer, size));

  while (done < size - 1)
  {
    #ifdef TCPV40HDRS
    // Work around for missing SO_RCVTIMEO in 16 bit IP stack.
    struct timeval timeout = {0};

    timeout.tv_sec = xio_socket_timeout();
    if (timeout.tv_sec)
    { fd_set waitlist;

      FD_ZERO(&waitlist);
      FD_SET (s_handle, &waitlist);

      switch (select(s_handle+1, &waitlist, NULL, NULL, &timeout))
      { case 0: // Timeout
          seterror(SOCETIMEDOUT);
          return NULL;
        case -1: // Error
          seterror();
          return NULL;
      }
    }
    #endif
    int rc = recv(s_handle, p, 1, 0);
    if( rc == 1 )
    { if (*p == '\r')
        continue;
      else if(*p == '\n')
        break;
      else
      { ++p;
        ++done;
      }
    } else
    { DEBUGLOG(("XIOsocket::gets: error %d\n", sock_errno()));
      if (!done)
      { if (rc == 0)
          eof = true;
        else
          seterror();
        return NULL;
      } else
        break;
    }
  }

  *p = 0;
  DEBUGLOG(("XIOsocket::gets: %s\n", buffer));
  return buffer;
}
开发者ID:OS2World,项目名称:MM-SOUND-PM123,代码行数:63,代码来源:xio_socket.cpp


示例18: lookup_hostname

/* Translates 'host_name', which must be a host name or a string representation
 * of an IP address, into a numeric IP address in '*addr'.  Returns 0 if
 * successful, otherwise a positive errno value.
 *
 * Most Open vSwitch code should not use this because it causes deadlocks:
 * getaddrinfo() sends out a DNS request but that starts a new flow for which
 * OVS must set up a flow, but it can't because it's waiting for a DNS reply.
 * The synchronous lookup also delays other activity.  (Of course we can solve
 * this but it doesn't seem worthwhile quite yet.)  */
int
lookup_hostname(const char *host_name, struct in_addr *addr)
{
    struct addrinfo *result;
    struct addrinfo hints;

    if (ip_parse(host_name, &addr->s_addr)) {
        return 0;
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_INET;

    switch (getaddrinfo(host_name, NULL, &hints, &result)) {
    case 0:
        *addr = ALIGNED_CAST(struct sockaddr_in *,
                             result->ai_addr)->sin_addr;
        freeaddrinfo(result);
        return 0;

#ifdef EAI_ADDRFAMILY
    case EAI_ADDRFAMILY:
#endif
    case EAI_NONAME:
    case EAI_SERVICE:
        return ENOENT;

    case EAI_AGAIN:
        return EAGAIN;

    case EAI_BADFLAGS:
    case EAI_FAMILY:
    case EAI_SOCKTYPE:
        return EINVAL;

    case EAI_FAIL:
        return EIO;

    case EAI_MEMORY:
        return ENOMEM;

#if defined (EAI_NODATA) && EAI_NODATA != EAI_NONAME
    case EAI_NODATA:
        return ENXIO;
#endif

#ifdef EAI_SYSTEM
    case EAI_SYSTEM:
        return sock_errno();
#endif

    default:
        return EPROTO;
    }
}
开发者ID:AlexanderFroemmgen,项目名称:ovs,代码行数:64,代码来源:socket-util.c


示例19: _MD_OS2GetHostName

PRStatus _MD_OS2GetHostName(char *name, PRUint32 namelen)
{
    PRIntn rv;

    rv = gethostname(name, (PRInt32) namelen);
    if (0 == rv) {
        return PR_SUCCESS;
    }
	_PR_MD_MAP_GETHOSTNAME_ERROR(sock_errno());
    return PR_FAILURE;
}
开发者ID:ppbao,项目名称:mozilla-os2,代码行数:11,代码来源:os2misc.c


示例20: APR_DECLARE

APR_DECLARE(apr_status_t) apr_socket_atmark(apr_socket_t *sock, int *atmark)
{
    int oobmark;

    if (ioctl(sock->socketdes, SIOCATMARK, (void*)&oobmark, sizeof(oobmark)) < 0) {
        return APR_OS2_STATUS(sock_errno());
    }

    *atmark = (oobmark != 0);

    return APR_SUCCESS;
}
开发者ID:Ga-vin,项目名称:apache,代码行数:12,代码来源:sockopt.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ sock_error函数代码示例发布时间:2022-05-30
下一篇:
C++ sock_close函数代码示例发布时间: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