本文整理汇总了C++中sock_get_error函数的典型用法代码示例。如果您正苦于以下问题:C++ sock_get_error函数的具体用法?C++ sock_get_error怎么用?C++ sock_get_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sock_get_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: netconn_connect
BOOL netconn_connect( netconn_t *conn, const struct sockaddr *sockaddr, unsigned int addr_len, int timeout )
{
BOOL ret = FALSE;
int res = 0;
ULONG state;
if (timeout > 0)
{
state = 1;
ioctlsocket( conn->socket, FIONBIO, &state );
}
if (connect( conn->socket, sockaddr, addr_len ) < 0)
{
res = sock_get_error( errno );
if (res == WSAEWOULDBLOCK || res == WSAEINPROGRESS)
{
#ifdef __REACTOS__
/* ReactOS: use select instead of poll */
fd_set outfd;
struct timeval tv;
FD_ZERO(&outfd);
FD_SET(conn->socket, &outfd);
tv.tv_sec = 0;
tv.tv_usec = timeout * 1000;
if (select( 0, NULL, &outfd, NULL, &tv ) > 0)
#else
struct pollfd pfd;
pfd.fd = conn->socket;
pfd.events = POLLOUT;
if (poll( &pfd, 1, timeout ) > 0)
#endif
ret = TRUE;
else
res = sock_get_error( errno );
}
}
else
ret = TRUE;
if (timeout > 0)
{
state = 0;
ioctlsocket( conn->socket, FIONBIO, &state );
}
if (!ret)
{
WARN("unable to connect to host (%d)\n", res);
set_last_error( res );
}
return ret;
}
示例2: NETCON_recv
/******************************************************************************
* NETCON_recv
* Basically calls 'recv()' unless we should use SSL
* number of chars received is put in *recvd
*/
DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, int flags,
int *recvd /* out */)
{
*recvd = 0;
if (!len)
return ERROR_SUCCESS;
if (!connection->useSSL)
{
*recvd = recv(connection->socketFD, buf, len, flags);
return *recvd == -1 ? sock_get_error(errno) : ERROR_SUCCESS;
}
else
{
#ifdef SONAME_LIBSSL
if(!connection->ssl_s) {
FIXME("not connected\n");
return ERROR_NOT_SUPPORTED;
}
*recvd = pSSL_read(connection->ssl_s, buf, len);
/* Check if EOF was received */
if(!*recvd && (pSSL_get_error(connection->ssl_s, *recvd)==SSL_ERROR_ZERO_RETURN
|| pSSL_get_error(connection->ssl_s, *recvd)==SSL_ERROR_SYSCALL))
return ERROR_SUCCESS;
return *recvd > 0 ? ERROR_SUCCESS : ERROR_INTERNET_CONNECTION_ABORTED;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
}
示例3: NETCON_send
/******************************************************************************
* NETCON_send
* Basically calls 'send()' unless we should use SSL
* number of chars send is put in *sent
*/
DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
int *sent /* out */)
{
if (!connection->useSSL)
{
*sent = send(connection->socketFD, msg, len, flags);
if (*sent == -1)
return sock_get_error(errno);
return ERROR_SUCCESS;
}
else
{
#ifdef SONAME_LIBSSL
if(!connection->ssl_s) {
FIXME("not connected\n");
return ERROR_NOT_SUPPORTED;
}
if (flags)
FIXME("SSL_write doesn't support any flags (%08x)\n", flags);
*sent = pSSL_write(connection->ssl_s, msg, len);
if (*sent < 1 && len)
return ERROR_INTERNET_CONNECTION_ABORTED;
return ERROR_SUCCESS;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
}
示例4: netconn_close
BOOL netconn_close( netconn_t *conn )
{
int res;
if (conn->secure)
{
heap_free( conn->peek_msg_mem );
conn->peek_msg_mem = NULL;
conn->peek_msg = NULL;
conn->peek_len = 0;
heap_free(conn->ssl_buf);
conn->ssl_buf = NULL;
heap_free(conn->extra_buf);
conn->extra_buf = NULL;
conn->extra_len = 0;
DeleteSecurityContext(&conn->ssl_ctx);
conn->secure = FALSE;
}
res = closesocket( conn->socket );
conn->socket = -1;
if (res == -1)
{
set_last_error( sock_get_error( errno ) );
return FALSE;
}
return TRUE;
}
示例5: NETCON_set_timeout
DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value)
{
int result;
struct timeval tv;
/* value is in milliseconds, convert to struct timeval */
if (value == INFINITE)
{
tv.tv_sec = 0;
tv.tv_usec = 0;
}
else
{
tv.tv_sec = value / 1000;
tv.tv_usec = (value % 1000) * 1000;
}
result = setsockopt(connection->socket, SOL_SOCKET,
send ? SO_SNDTIMEO : SO_RCVTIMEO, (void*)&tv,
sizeof(tv));
if (result == -1)
{
WARN("setsockopt failed (%s)\n", strerror(errno));
return sock_get_error(errno);
}
return ERROR_SUCCESS;
}
示例6: NETCON_send
/******************************************************************************
* NETCON_send
* Basically calls 'send()' unless we should use SSL
* number of chars send is put in *sent
*/
BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
int *sent /* out */)
{
if (!NETCON_connected(connection)) return FALSE;
if (!connection->useSSL)
{
*sent = send(connection->socketFD, msg, len, flags);
if (*sent == -1)
{
INTERNET_SetLastError(sock_get_error(errno));
return FALSE;
}
return TRUE;
}
else
{
#ifdef SONAME_LIBSSL
if (flags)
FIXME("SSL_write doesn't support any flags (%08x)\n", flags);
*sent = pSSL_write(connection->ssl_s, msg, len);
if (*sent < 1 && len)
return FALSE;
return TRUE;
#else
return FALSE;
#endif
}
}
示例7: sock_wake_up
/* wake anybody waiting on the socket event or send the associated message */
static void sock_wake_up( struct sock *sock )
{
unsigned int events = sock->pmask & sock->mask;
int i;
if ( !events ) return;
if (sock->event)
{
if (debug_level) fprintf(stderr, "signalling events %x ptr %p\n", events, sock->event );
set_event( sock->event );
}
if (sock->window)
{
if (debug_level) fprintf(stderr, "signalling events %x win %08x\n", events, sock->window );
for (i = 0; i < FD_MAX_EVENTS; i++)
{
int event = event_bitorder[i];
if (sock->pmask & (1 << event))
{
lparam_t lparam = (1 << event) | (sock_get_error(sock->errors[event]) << 16);
post_message( sock->window, sock->message, sock->wparam, lparam );
}
}
sock->pmask = 0;
sock_reselect( sock );
}
}
示例8: netconn_send
BOOL netconn_send( netconn_t *conn, const void *msg, size_t len, int *sent )
{
if (!netconn_connected( conn )) return FALSE;
if (conn->secure)
{
const BYTE *ptr = msg;
size_t chunk_size;
*sent = 0;
while(len) {
chunk_size = min(len, conn->ssl_sizes.cbMaximumMessage);
if(!send_ssl_chunk(conn, ptr, chunk_size))
return FALSE;
*sent += chunk_size;
ptr += chunk_size;
len -= chunk_size;
}
return TRUE;
}
if ((*sent = sock_send( conn->socket, msg, len, 0 )) == -1)
{
set_last_error( sock_get_error( errno ) );
return FALSE;
}
return TRUE;
}
示例9: NETCON_send
/******************************************************************************
* NETCON_send
* Basically calls 'send()' unless we should use SSL
* number of chars send is put in *sent
*/
DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
int *sent /* out */)
{
if(!connection->secure)
{
*sent = sock_send(connection->socket, msg, len, flags);
if (*sent == -1)
return sock_get_error(errno);
return ERROR_SUCCESS;
}
else
{
const BYTE *ptr = msg;
size_t chunk_size;
*sent = 0;
while(len) {
chunk_size = min(len, connection->ssl_sizes.cbMaximumMessage);
if(!send_ssl_chunk(connection, ptr, chunk_size))
return ERROR_INTERNET_SECURITY_CHANNEL_ERROR;
*sent += chunk_size;
ptr += chunk_size;
len -= chunk_size;
}
return ERROR_SUCCESS;
}
}
示例10: NETCON_set_timeout
DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value)
{
int result;
struct timeval tv;
/* FIXME: we should probably store the timeout in the connection to set
* when we do connect */
if (!NETCON_connected(connection))
return ERROR_SUCCESS;
/* value is in milliseconds, convert to struct timeval */
tv.tv_sec = value / 1000;
tv.tv_usec = (value % 1000) * 1000;
result = setsockopt(connection->socketFD, SOL_SOCKET,
send ? SO_SNDTIMEO : SO_RCVTIMEO, &tv,
sizeof(tv));
if (result == -1)
{
WARN("setsockopt failed (%s)\n", strerror(errno));
return sock_get_error(errno);
}
return ERROR_SUCCESS;
}
示例11: netconn_close
BOOL netconn_close( netconn_t *conn )
{
int res;
#ifdef SONAME_LIBSSL
if (conn->secure)
{
heap_free( conn->peek_msg_mem );
conn->peek_msg_mem = NULL;
conn->peek_msg = NULL;
conn->peek_len = 0;
pSSL_shutdown( conn->ssl_conn );
pSSL_free( conn->ssl_conn );
conn->ssl_conn = NULL;
conn->secure = FALSE;
}
#endif
res = closesocket( conn->socket );
conn->socket = -1;
if (res == -1)
{
set_last_error( sock_get_error( errno ) );
return FALSE;
}
return TRUE;
}
示例12: NETCON_close
/******************************************************************************
* NETCON_close
* Basically calls 'close()' unless we should use SSL
*/
BOOL NETCON_close(WININET_NETCONNECTION *connection)
{
int result;
if (!NETCON_connected(connection)) return FALSE;
#ifdef SONAME_LIBSSL
if (connection->useSSL)
{
HeapFree(GetProcessHeap(),0,connection->peek_msg_mem);
connection->peek_msg = NULL;
connection->peek_msg_mem = NULL;
connection->peek_len = 0;
pSSL_shutdown(connection->ssl_s);
pSSL_free(connection->ssl_s);
connection->ssl_s = NULL;
connection->useSSL = FALSE;
}
#endif
result = closesocket(connection->socketFD);
connection->socketFD = -1;
if (result == -1)
{
INTERNET_SetLastError(sock_get_error(errno));
return FALSE;
}
return TRUE;
}
示例13: create_netconn_socket
static DWORD create_netconn_socket(server_t *server, netconn_t *netconn, DWORD timeout)
{
int result;
ULONG flag;
assert(server->addr_len);
result = netconn->socket = socket(server->addr.ss_family, SOCK_STREAM, 0);
if(result != -1) {
flag = 1;
ioctlsocket(netconn->socket, FIONBIO, &flag);
result = connect(netconn->socket, (struct sockaddr*)&server->addr, server->addr_len);
if(result == -1)
{
if (sock_get_error(errno) == WSAEINPROGRESS) {
struct pollfd pfd;
int res;
pfd.fd = netconn->socket;
pfd.events = POLLOUT;
res = poll(&pfd, 1, timeout);
if (!res)
{
closesocket(netconn->socket);
netconn->socket = -1;
return ERROR_INTERNET_CANNOT_CONNECT;
}
else if (res > 0)
{
int err;
socklen_t len = sizeof(err);
if (!getsockopt(netconn->socket, SOL_SOCKET, SO_ERROR, (void *)&err, &len) && !err)
result = 0;
}
}
}
if(result == -1)
{
closesocket(netconn->socket);
netconn->socket = -1;
}
else {
flag = 0;
ioctlsocket(netconn->socket, FIONBIO, &flag);
}
}
if(result == -1)
return ERROR_INTERNET_CANNOT_CONNECT;
#ifdef TCP_NODELAY
flag = 1;
result = setsockopt(netconn->socket, IPPROTO_TCP, TCP_NODELAY, (void*)&flag, sizeof(flag));
if(result < 0)
WARN("setsockopt(TCP_NODELAY) failed\n");
#endif
return ERROR_SUCCESS;
}
示例14: netconn_recv
BOOL netconn_recv( netconn_t *conn, void *buf, size_t len, int flags, int *recvd )
{
*recvd = 0;
if (!netconn_connected( conn )) return FALSE;
if (!len) return TRUE;
if (conn->secure)
{
SIZE_T size, cread;
BOOL res, eof;
if (conn->peek_msg)
{
*recvd = min( len, conn->peek_len );
memcpy( buf, conn->peek_msg, *recvd );
conn->peek_len -= *recvd;
conn->peek_msg += *recvd;
if (conn->peek_len == 0)
{
heap_free( conn->peek_msg_mem );
conn->peek_msg_mem = NULL;
conn->peek_msg = NULL;
}
/* check if we have enough data from the peek buffer */
if (!(flags & MSG_WAITALL) || *recvd == len) return TRUE;
}
size = *recvd;
do {
res = read_ssl_chunk(conn, (BYTE*)buf+size, len-size, &cread, &eof);
if(!res) {
WARN("read_ssl_chunk failed\n");
if(!size)
return FALSE;
break;
}
if(eof) {
TRACE("EOF\n");
break;
}
size += cread;
} while(!size || ((flags & MSG_WAITALL) && size < len));
TRACE("received %ld bytes\n", size);
*recvd = size;
return TRUE;
}
if ((*recvd = sock_recv( conn->socket, buf, len, flags )) == -1)
{
set_last_error( sock_get_error( errno ) );
return FALSE;
}
return TRUE;
}
示例15: netconn_connect
BOOL netconn_connect( netconn_t *conn, const struct sockaddr *sockaddr, unsigned int addr_len, int timeout )
{
BOOL ret = FALSE;
int res = 0, state;
if (timeout > 0)
{
state = 1;
ioctlsocket( conn->socket, FIONBIO, &state );
}
if (connect( conn->socket, sockaddr, addr_len ) < 0)
{
res = sock_get_error( errno );
if (res == WSAEWOULDBLOCK || res == WSAEINPROGRESS)
{
fd_set outfd;
struct timeval tv;
FD_ZERO(&outfd);
FD_SET(conn->socket, &outfd);
tv.tv_sec = 0;
tv.tv_usec = timeout * 1000;
if (select( 0, NULL, &outfd, NULL, &tv ) > 0)
ret = TRUE;
else
res = sock_get_error( errno );
}
}
else
ret = TRUE;
if (timeout > 0)
{
state = 0;
ioctlsocket( conn->socket, FIONBIO, &state );
}
if (!ret)
{
WARN("unable to connect to host (%d)\n", res);
set_last_error( res );
}
return ret;
}