本文整理汇总了C++中sock_error函数的典型用法代码示例。如果您正苦于以下问题:C++ sock_error函数的具体用法?C++ sock_error怎么用?C++ sock_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sock_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _max_listen
server_socket<T>::server_socket(unsigned int listen_port, string ipaddress,int max_listen):_ipaddress(ipaddress),_listen_port(listen_port), _max_listen(max_listen)
{
T addr(std::to_string(_listen_port),_ipaddress);
struct addrinfo *p = addr.get_result();
for(p = addr.get_result(); p != NULL; p = p->ai_next)
{
if (bind(this->get_sockfd(), p->ai_addr, p->ai_addrlen) == -1)
{
close(this->get_sockfd());
throw sock_error("Error in Bind");
continue;
}
else
{
break;
}
}
if (p == NULL)
{
//bind error, throw expection
return;
}
if (listen(this->get_sockfd(), _max_listen) < 0)
{
throw sock_error("Error in Listen.");
}
}
示例2: wait_for_serversock
static connection_t *_accept_connection(void)
{
int sock;
connection_t *con;
char *ip;
int serversock;
serversock = wait_for_serversock(100);
if(serversock < 0)
return NULL;
/* malloc enough room for a full IP address (including ipv6) */
ip = (char *)malloc(MAX_ADDR_LEN);
sock = sock_accept(serversock, ip, MAX_ADDR_LEN);
if (sock >= 0)
{
con = connection_create (sock, serversock, ip);
if (con == NULL)
free (ip);
return con;
}
if (!sock_recoverable(sock_error()))
WARN2("accept() failed with error %d: %s", sock_error(), strerror(sock_error()));
free(ip);
return NULL;
}
示例3: startConnection
static SOCKET startConnection(void)
{
HERROR_WRITE(HERROR_INFO, "[Lanc. serveur] Initialisation du serveur...");
/* Initialisation Windows */
initW32();
/* Socket */
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN sin;
if(sock == INVALID_SOCKET)
sock_error("socket()");
sin.sin_addr.s_addr = htonl(INADDR_ANY); /* Adresse */
sin.sin_port = htons(PORT); /* Port */
sin.sin_family = AF_INET; /* Protocole : TCP */
/* On lie le socket */
if(bind(sock, (SOCKADDR *)&sin, sizeof(sin)) == SOCKET_ERROR)
sock_error("bind()");
HERROR_WRITE(-1, "terminee");
/* On passe en mode écoute */
if(listen(sock, MAX_CLIENTS) == SOCKET_ERROR)
sock_error("listen()");
HERROR_WRITE(HERROR_INFO, "[Lanc. serveur] Serveur en mode ecoute");
return sock;
}
示例4: sock_connect_error
int sock_connect_error(const sock_t sock)
{
struct sockaddr sa;
unsigned len;
char temp;
sa.sa_family = AF_INET;
len = sizeof(sa);
/* we don't actually care about the peer name, we're just checking if
* we're connected or not */
if (getpeername(sock, &sa, &len) == 0)
{
return 0;
}
/* it's possible that the error wasn't ENOTCONN, so if it wasn't,
* return that */
#ifdef _WIN32
if (sock_error() != WSAENOTCONN) return sock_error();
#else
if (sock_error() != ENOTCONN) return sock_error();
#endif
/* load the correct error into errno through error slippage */
recv(sock, &temp, 1, 0);
return sock_error();
}
示例5: INFO0
static void *log_commit_thread (void *arg)
{
INFO0 ("started");
while (1)
{
int ret = util_timed_wait_for_fd (logger_fd[0], 5000);
if (ret == 0) continue;
if (ret > 0)
{
char cm[80];
ret = pipe_read (logger_fd[0], cm, sizeof cm);
if (ret > 0)
{
// fprintf (stderr, "logger woken with %d\n", ret);
log_commit_entries ();
continue;
}
}
if (ret < 0 && sock_recoverable (sock_error()))
continue;
int err = sock_error();
sock_close (logger_fd[0]);
sock_close (logger_fd[1]);
if (worker_count)
{
worker_control_create (logger_fd);
ERROR1 ("logger received code %d", err);
continue;
}
// fprintf (stderr, "logger closed with zero workers\n");
break;
}
return NULL;
}
示例6: sock_init_connection
SOCKET sock_init_connection(const char *address, int port, int maxcli)
{
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN sin = { 0 };
if(sock == INVALID_SOCKET)
{
int err = sock_error();
fprintf (stderr, "socket() : %s\n", sock_err_message(err));
return err;
}
if(!sock_getAddr(sin, address))
{
fprintf (stderr, "connection failed\n");
return EXIT_FAILURE;
}
sin.sin_port = htons(port);
sin.sin_family = AF_INET;
if(address != NULL && strlen(address) > 0)
{
if(connect(sock,(SOCKADDR *) &sin, sizeof(SOCKADDR)) == SOCKET_ERROR)
{
int err = sock_error();
fprintf (stderr, "connect() : %s\n", sock_err_message(err));
return err;
}
}
else
{
if(bind(sock,(SOCKADDR *) &sin, sizeof sin) == SOCKET_ERROR)
{
int err = sock_error();
fprintf (stderr, "socket() : %s\n", sock_err_message(err));
return err;
}
if(listen(sock, maxcli) == SOCKET_ERROR)
{
int err = sock_error();
fprintf (stderr, "listen() : %s\n", sock_err_message(err));
return err;
}
}
return sock;
}
示例7: sock_connected
int sock_connected (sock_t sock, int timeout)
{
struct pollfd check;
int val = SOCK_ERROR;
socklen_t size = sizeof val;
check.fd = sock;
check.events = POLLOUT;
switch (poll (&check, 1, timeout*1000))
{
case 0:
return SOCK_TIMEOUT;
default:
/* on windows getsockopt.val is defined as char* */
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) == 0)
{
if (val == 0)
return 1;
sock_set_error (val);
}
/* fall through */
case -1:
if (sock_recoverable (sock_error()))
return 0;
return SOCK_ERROR;
}
}
示例8: _connect
arg_t _connect(void)
{
uint8_t flag;
struct socket *s = sock_get(fd, &flag);
struct sockaddr_in sin;
if (s == NULL)
return -1;
if (s->s_state == SS_CONNECTING) {
udata.u_error = EALREADY;
return -1;
}
if (s->s_state == SS_UNCONNECTED && sock_autobind(s))
return -1;
if (s->s_state == SS_BOUND) {
if (sa_getremote(uaddr, &sin) == -1)
return -1;
s->s_addr[SADDR_DST].addr = sin.sin_addr.s_addr;
s->s_addr[SADDR_DST].port = sin.sin_port;
if (net_connect(s))
return -1;
if (sock_wait_leave(s, 0, SS_CONNECTING)) {
/* API oddity, thanks Berkeley */
if (udata.u_error == EAGAIN)
udata.u_error = EINPROGRESS;
return -1;
}
return sock_error(s);
}
udata.u_error = EINVAL;
return -1;
}
示例9: ASSERT
uint32_t ClientNetSocket::receive_buf(uint8_t* buf, uint32_t max_size, bool& shutdown)
{
uint8_t* pos = buf;
ASSERT(_peer != INVALID_SOCKET);
shutdown = false;
while (max_size) {
int now;
if ((now = ::recv(_peer, (char*)pos, max_size, 0)) <= 0) {
if (now == 0) {
shutdown = true;
break; // a case where fin is received, but before that, there is a msg
}
int err = sock_error();
if (err == WOULDBLOCK_ERR) {
break;
}
if (err == INTERRUPTED_ERR) {
continue;
}
LOG_INFO("receive in connection_id=%d failed errno=%s", _id, sock_err_message(err));
throw ClientNetSocket::ReceiveException();
}
max_size -= now;
pos += now;
}
return (pos - buf);
}
示例10: _accept
/* Note: We don't do address return, the library can handle it */
arg_t _accept(void)
{
uint8_t flag;
struct socket *s = sock_get(fd, &flag);
struct socket *n;
int8_t nfd;
if (s == NULL)
return -1;
if (s->s_state == SS_LISTENING) {
udata.u_error = EALREADY;
return -1;
}
/* Needs locking versus interrupts */
while ((n = sock_pending(s)) == NULL) {
if (psleep_flags(s, flag))
return -1;
if (s->s_error)
return sock_error(s);
}
if ((nfd = make_socket(&socktypes[SOCKTYPE_TCP], &n)) == -1)
return -1;
n->s_state = SS_CONNECTED;
return nfd;
}
示例11: ClientTest
ClientTest(const QString &_host, int _port, const QString &_proto, const QString &_authzid, const QString &_realm, const QString &_user, const QString &_pass, bool _no_authzid, bool _no_realm) :
host(_host),
proto(_proto),
authzid(_authzid),
realm(_realm),
user(_user),
pass(_pass),
port(_port),
no_authzid(_no_authzid),
no_realm(_no_realm),
sock_done(false),
waitCycles(0)
{
sock = new QTcpSocket(this);
connect(sock, SIGNAL(connected()), SLOT(sock_connected()));
connect(sock, SIGNAL(readyRead()), SLOT(sock_readyRead()));
connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(sock_error(QAbstractSocket::SocketError)));
sasl = new QCA::SASL(this);
connect(sasl, SIGNAL(clientStarted(bool, const QByteArray &)), SLOT(sasl_clientFirstStep(bool, const QByteArray &)));
connect(sasl, SIGNAL(nextStep(const QByteArray &)), SLOT(sasl_nextStep(const QByteArray &)));
connect(sasl, SIGNAL(needParams(const QCA::SASL::Params &)), SLOT(sasl_needParams(const QCA::SASL::Params &)));
connect(sasl, SIGNAL(authenticated()), SLOT(sasl_authenticated()));
connect(sasl, SIGNAL(readyRead()), SLOT(sasl_readyRead()));
connect(sasl, SIGNAL(readyReadOutgoing()), SLOT(sasl_readyReadOutgoing()));
connect(sasl, SIGNAL(error()), SLOT(sasl_error()));
}
示例12: connection_client_setup
static int connection_client_setup (connection_queue_t *node) {
int err;
err = -ENOENT;
if (node->con->con_timeout <= time(NULL))
return err;
global_lock();
err = client_create (&node->client, node->con, node->parser);
if (err < 0)
goto out_fail;
if (sock_set_blocking (node->con->sock, 0) || sock_set_nodelay (node->con->sock)) {
if (! sock_recoverable(sock_error())) {
node->con->error = 1;
err = -EINVAL;
goto out_fail;
}
err = -EINPROGRESS;
client_send_403 (node->client, "failed to set tcp options on client connection, dropping");
goto out_fail;
}
global_unlock();
return 0;
out_fail:
global_unlock();
return err;
}
示例13: _connect
arg_t _connect(void)
{
uint8_t flag;
struct socket *s = sock_get(fd, &flag);
struct sockaddr_in sin;
if (s == NULL)
return -1;
if (s->s_state == SS_CONNECTING) {
udata.u_error = EALREADY;
return -1;
}
if (s->s_state == SS_UNCONNECTED && sock_autobind(s))
return -1;
if (s->s_state == SS_BOUND) {
if (sa_getremote(uaddr, &sin) == -1)
return -1;
s->s_addr[SADDR_DST].addr = sin.sin_addr.s_addr;
s->s_addr[SADDR_DST].port = sin.sin_port;
s->s_state = SS_CONNECTING;
/* Protocol op to kick off */
}
do {
/* FIXME: return EINPROGRESS not EINTR for SS_CONNECTING */
if (psleep_flags(s, flag))
return -1;
/* Protocol state check */
} while (s->s_state == SS_CONNECTING);
return sock_error(s);
}
示例14: l2cap_sock_sendmsg
static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
struct msghdr *msg, size_t len)
#endif
{
struct sock *sk = sock->sk;
struct l2cap_chan *chan = l2cap_pi(sk)->chan;
int err;
BT_DBG("sock %p, sk %p", sock, sk);
err = sock_error(sk);
if (err)
return err;
if (msg->msg_flags & MSG_OOB)
return -EOPNOTSUPP;
if (sk->sk_state != BT_CONNECTED)
return -ENOTCONN;
lock_sock(sk);
err = bt_sock_wait_ready(sk, msg->msg_flags);
release_sock(sk);
if (err)
return err;
l2cap_chan_lock(chan);
err = l2cap_chan_send(chan, msg, len);
l2cap_chan_unlock(chan);
return err;
}
示例15: sk_stream_wait_connect
/**
* sk_stream_wait_connect - Wait for a socket to get into the connected state
* @sk: sock to wait on
* @timeo_p: for how long to wait
*
* Must be called with the socket locked.
*/
int sk_stream_wait_connect(struct sock *sk, long *timeo_p)
{
struct task_struct *tsk = current;
DEFINE_WAIT(wait);
int done;
do {
int err = sock_error(sk);
if (err)
return err;
if ((1 << sk->sk_state) & ~(TCPF_SYN_SENT | TCPF_SYN_RECV))
return -EPIPE;
if (!*timeo_p)
return -EAGAIN;
if (signal_pending(tsk))
return sock_intr_errno(*timeo_p);
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
sk->sk_write_pending++;
done = sk_wait_event(sk, timeo_p,
!sk->sk_err &&
!((1 << sk->sk_state) &
~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)));
finish_wait(sk_sleep(sk), &wait);
sk->sk_write_pending--;
} while (!done);
return 0;
}