本文整理汇总了C++中sock_errno函数的典型用法代码示例。如果您正苦于以下问题:C++ sock_errno函数的具体用法?C++ sock_errno怎么用?C++ sock_errno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sock_errno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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 ;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例8: xstrerror_a
/*
* xstrerror() - sock_errno/strerror-like wrapper
*/
const char *
xstrerror_a(void)
{ int ierr;
ierr = sock_errno();
return xbstrerror_i(ierr);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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
}