本文整理汇总了C++中dill_slow函数的典型用法代码示例。如果您正苦于以下问题:C++ dill_slow函数的具体用法?C++ dill_slow怎么用?C++ dill_slow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dill_slow函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: dill_tcp_close
int dill_tcp_close(int s, int64_t deadline) {
int err;
/* Listener socket needs no special treatment. */
if(dill_hquery(s, dill_tcp_listener_type)) {
return dill_hclose(s);
}
struct dill_tcp_conn *self = dill_hquery(s, dill_tcp_type);
if(dill_slow(!self)) return -1;
if(dill_slow(self->inerr || self->outerr)) {err = ECONNRESET; goto error;}
/* If not done already, flush the outbound data and start the terminal
handshake. */
if(!self->outdone) {
int rc = dill_tcp_done(s, deadline);
if(dill_slow(rc < 0)) {err = errno; goto error;}
}
/* Now we are going to read all the inbound data until we reach end of the
stream. That way we can be sure that the peer either received all our
data or consciously closed the connection without reading all of it. */
int rc = dill_tcp_brecvl(&self->bvfs, NULL, NULL, deadline);
dill_assert(rc < 0);
if(dill_slow(errno != EPIPE)) {err = errno; goto error;}
dill_tcp_hclose(&self->hvfs);
return 0;
error:
dill_tcp_hclose(&self->hvfs);
errno = err;
return -1;
}
开发者ID:jimjag,项目名称:libdill,代码行数:28,代码来源:tcp.c
示例2: tcpaccept
int tcpaccept(int s, int64_t deadline) {
int err;
struct tcplistener *lst = hdata(s, tcplistener_type);
if(dill_slow(!lst)) return -1;
/* Try to get new connection in a non-blocking way. */
ipaddr addr;
socklen_t addrlen;
int as = dsaccept(lst->fd, (struct sockaddr*)&addr, &addrlen, deadline);
if(dill_slow(as < 0)) return -1;
tcptune(as);
/* Create the object. */
struct tcpconn *conn = tcpconn_create();
if(dill_slow(!conn)) {err = errno; goto error1;}
conn->fd = as;
conn->addr = addr;
/* Bind the object to a handle. */
int hndl = bsock(tcpconn_type, conn, &tcpconn_vfptrs);
if(dill_slow(hndl < 0)) {err = errno; goto error2;}
return hndl;
error2:
tcpconn_destroy(conn);
error1:;
int rc = dsclose(s);
dill_assert(rc == 0);
errno = err;
return -1;
}
开发者ID:ConfusedReality,项目名称:pkg_websocket_dillsocks,代码行数:27,代码来源:tcp.c
示例3: dill_tls_brecvl
static int dill_tls_brecvl(struct dill_bsock_vfs *bvfs,
struct dill_iolist *first, struct dill_iolist *last, int64_t deadline) {
struct dill_tls_sock *self = dill_cont(bvfs, struct dill_tls_sock, bvfs);
if(dill_slow(self->indone)) {errno = EPIPE; return -1;}
if(dill_slow(self->inerr)) {errno = ECONNRESET; return -1;}
self->deadline = deadline;
struct dill_iolist *it = first;
while(1) {
uint8_t *base = it->iol_base;
size_t len = it->iol_len;
while(1) {
ERR_clear_error();
int rc = SSL_read(self->ssl, base, len);
if(dill_tls_followup(self, rc)) {
if(dill_slow(errno != 0)) {
if(errno == EPIPE) self->indone = 1;
else self->inerr = 1;
return -1;
}
if(rc == len) break;
base += rc;
len -= rc;
}
}
if(it == last) break;
it = it->iol_next;
}
return 0;
}
开发者ID:jimjag,项目名称:libdill,代码行数:29,代码来源:tls.c
示例4: dill_tls_detach
int dill_tls_detach(int s, int64_t deadline) {
int err;
struct dill_tls_sock *self = dill_hquery(s, dill_tls_type);
if(dill_slow(!self)) return -1;
if(dill_slow(self->inerr || self->outerr)) {err = ECONNRESET; goto error;}
/* Start terminal TLS handshake. */
if(!self->outdone) {
int rc = dill_tls_done(s, deadline);
if(dill_slow(rc < 0)) {err = errno; goto error;}
}
/* Wait for the handshake acknowledgement from the peer. */
if(!self->indone) {
while(1) {
ERR_clear_error();
int rc = SSL_shutdown(self->ssl);
if(rc == 1) break;
if(dill_tls_followup(self, rc)) {err = errno; goto error;}
}
}
int u = self->u;
self->u = -1;
dill_tls_hclose(&self->hvfs);
return u;
error:
dill_tls_hclose(&self->hvfs);
errno = err;
return -1;
}
开发者ID:jimjag,项目名称:libdill,代码行数:28,代码来源:tls.c
示例5: msendl
int msendl(int s, struct iolist *first, struct iolist *last, int64_t deadline) {
struct msock_vfs *m = hquery(s, msock_type);
if(dill_slow(!m)) return -1;
if(dill_slow(!first || !last || last->iol_next)) {
errno = EINVAL; return -1;}
return m->msendl(m, first, last, deadline);
}
开发者ID:reqshark,项目名称:libdill,代码行数:7,代码来源:msock.c
示例6: dill_iolcheck
int dill_iolcheck(struct iolist *first, struct iolist *last,
size_t *nbufs, size_t *nbytes) {
if(!first && !last) {
if(nbufs) *nbufs = 0;
if(nbytes) *nbytes = 0;
return 0;
}
if(dill_slow(!first || !last || last->iol_next)) {
errno = EINVAL; return -1;}
size_t nbf = 0, nbt = 0, res = 0;
struct iolist *it;
for(it = first; it; it = it->iol_next) {
if(dill_slow(it->iol_rsvd || (!it->iol_next && it != last)))
goto error;
it->iol_rsvd = 1;
nbf++;
nbt += it->iol_len;
}
for(it = first; it; it = it->iol_next) it->iol_rsvd = 0;
if(nbufs) *nbufs = nbf;
if(nbytes) *nbytes = nbt;
return 0;
error:;
struct iolist *it2;
for(it2 = first; it2 != it; it2 = it2->iol_next) it->iol_rsvd = 0;
errno = EINVAL;
return -1;
}
开发者ID:jimjag,项目名称:libdill,代码行数:28,代码来源:iol.c
示例7: dill_term_detach
int dill_term_detach(int s, int64_t deadline) {
int err;
struct dill_term_sock *self = dill_hquery(s, dill_term_type);
if(dill_slow(!self)) return -1;
if(!self->outdone) {
int rc = dill_term_done(s, deadline);
if(dill_slow(rc < 0)) {err = errno; goto error;}
}
if(!self->indone) {
while(1) {
struct dill_iolist iol = {NULL, SIZE_MAX, NULL, 0};
ssize_t sz = dill_term_mrecvl(&self->mvfs, &iol, &iol, deadline);
if(sz < 0) {
if(errno == EPIPE) break;
err = errno;
goto error;
}
}
}
int u = self->u;
if(!self->mem) free(self);
return u;
error:;
int rc = dill_hclose(s);
dill_assert(rc == 0);
errno = err;
return -1;
}
开发者ID:jimjag,项目名称:libdill,代码行数:28,代码来源:term.c
示例8: sf_send
static int sf_send(int s, const void *buf, size_t len, int64_t deadline) {
struct sf *conn = msockdata(s, sf_type);
if(dill_slow(!conn)) return -1;
if(dill_slow(conn->res != SF_ACTIVE)) {errno = ECONNRESET; return -1;}
/* Create a message object. */
struct msg msg;
msg.buf = malloc(len);
if(dill_slow(!msg.buf)) {errno = ENOMEM; return -1;}
memcpy(msg.buf, buf, len);
msg.len = len;
/* Send it to the worker. */
int rc = chsend(conn->ochan, &msg, sizeof(msg), deadline);
if(dill_fast(rc >= 0)) return 0;
/* Closed pipe means that the connection was terminated. */
if(errno == EPIPE) {
dill_assert(conn->ores == SF_RESET);
conn->res = SF_RESET;
errno = ECONNRESET;
}
/* Clean up. */
int err = errno;
free(msg.buf);
errno = err;
return -1;
}
开发者ID:ConfusedReality,项目名称:pkg_websocket_dillsocks,代码行数:25,代码来源:sf.c
示例9: dill_tcp_accept_mem
int dill_tcp_accept_mem(int s, struct dill_ipaddr *addr,
struct dill_tcp_storage *mem, int64_t deadline) {
int err;
if(dill_slow(!mem)) {err = EINVAL; goto error1;}
/* Retrieve the listener object. */
struct dill_tcp_listener *lst = dill_hquery(s, dill_tcp_listener_type);
if(dill_slow(!lst)) {err = errno; goto error1;}
/* Try to get new connection in a non-blocking way. */
socklen_t addrlen = sizeof(struct dill_ipaddr);
int as = dill_fd_accept(lst->fd, (struct sockaddr*)addr, &addrlen,
deadline);
if(dill_slow(as < 0)) {err = errno; goto error1;}
/* Set it to non-blocking mode. */
int rc = dill_fd_unblock(as);
if(dill_slow(rc < 0)) {err = errno; goto error2;}
/* Create the handle. */
int h = dill_tcp_makeconn(as, mem);
if(dill_slow(h < 0)) {err = errno; goto error2;}
return h;
error2:
dill_fd_close(as);
error1:
errno = err;
return -1;
}
开发者ID:jimjag,项目名称:libdill,代码行数:25,代码来源:tcp.c
示例10: tcpconnect
int tcpconnect(const ipaddr *addr, int64_t deadline) {
int err;
/* Open a socket. */
int s = socket(ipfamily(addr), SOCK_STREAM, 0);
if(dill_slow(s < 0)) return -1;
tcptune(s);
/* Connect to the remote endpoint. */
int rc = dsconnect(s, ipsockaddr(addr), iplen(addr), deadline);
if(dill_slow(rc < 0)) return -1;
/* Create the object. */
struct tcpconn *conn = tcpconn_create();
if(dill_slow(!conn)) {err = errno; goto error1;}
conn->fd = s;
conn->addr = *addr;
/* Bind the object to a sock handle. */
int bs = bsock(tcpconn_type, conn, &tcpconn_vfptrs);
if(dill_slow(bs < 0)) {err = errno; goto error2;}
return bs;
error2:
tcpconn_destroy(conn);
error1:
rc = dsclose(s);
dill_assert(rc == 0);
errno = err;
return -1;
}
开发者ID:ConfusedReality,项目名称:pkg_websocket_dillsocks,代码行数:26,代码来源:tcp.c
示例11: dsrecv
int dsrecv(int s, void *buf, size_t *len, int64_t deadline) {
size_t received = 0;
while(1) {
ssize_t sz = recv(s, ((char*)buf) + received, *len - received, 0);
if(dill_slow(sz == 0)) {
*len = received;
errno = ECONNRESET;
return -1;
}
if(sz < 0) {
if(dill_slow(errno != EWOULDBLOCK && errno != EAGAIN)) {
*len = received;
return -1;
}
}
else {
received += sz;
if(received >= *len)
return 0;
}
int rc = fdin(s, deadline);
if(dill_slow(rc < 0)) {
*len = received;
return -1;
}
}
}
开发者ID:ConfusedReality,项目名称:pkg_websocket_dillsocks,代码行数:27,代码来源:helpers.c
示例12: udp_sendl_
int udp_sendl_(struct msock_vfs *mvfs, const struct ipaddr *addr,
struct iolist *first, struct iolist *last) {
struct udp_sock *obj = dill_cont(mvfs, struct udp_sock, mvfs);
/* If no destination IP address is provided, fall back to the stored one. */
const struct ipaddr *dstaddr = addr;
if(!dstaddr) {
if(dill_slow(!obj->hasremote)) {errno = EINVAL; return -1;}
dstaddr = &obj->remote;
}
struct msghdr hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.msg_name = (void*)ipaddr_sockaddr(dstaddr);
hdr.msg_namelen = ipaddr_len(dstaddr);
/* Make a local iovec array. */
/* TODO: This is dangerous, it may cause stack overflow.
There should probably be a on-heap per-socket buffer for that. */
size_t niov;
int rc = iol_check(first, last, &niov, NULL);
if(dill_slow(rc < 0)) return -1;
struct iovec iov[niov];
iol_toiov(first, iov);
hdr.msg_iov = (struct iovec*)iov;
hdr.msg_iovlen = niov;
ssize_t sz = sendmsg(obj->fd, &hdr, 0);
if(dill_fast(sz >= 0)) return 0;
if(errno == EAGAIN || errno == EWOULDBLOCK) return 0;
return -1;
}
开发者ID:reqshark,项目名称:libdill,代码行数:28,代码来源:udp.c
示例13: dill_prefix_attach_mem
int dill_prefix_attach_mem(int s, size_t hdrlen, int flags,
struct dill_prefix_storage *mem) {
int err;
if(dill_slow(!mem || hdrlen == 0)) {err = EINVAL; goto error;}
/* Take ownership of the underlying socket. */
s = dill_hown(s);
if(dill_slow(s < 0)) {err = errno; goto error;}
/* Check whether underlying socket is a bytestream. */
void *q = dill_hquery(s, dill_bsock_type);
if(dill_slow(!q && errno == ENOTSUP)) {err = EPROTO; goto error;}
if(dill_slow(!q)) {err = errno; goto error;}
/* Create the object. */
struct dill_prefix_sock *self = (struct dill_prefix_sock*)mem;
self->hvfs.query = dill_prefix_hquery;
self->hvfs.close = dill_prefix_hclose;
self->mvfs.msendl = dill_prefix_msendl;
self->mvfs.mrecvl = dill_prefix_mrecvl;
self->u = s;
self->hdrlen = hdrlen;
self->bigendian = !(flags & DILL_PREFIX_LITTLE_ENDIAN);
self->inerr = 0;
self->outerr = 0;
self->mem = 1;
/* Create the handle. */
int h = dill_hmake(&self->hvfs);
if(dill_slow(h < 0)) {int err = errno; goto error;}
return h;
error:
if(s >= 0) dill_hclose(s);
errno = err;
return -1;
}
开发者ID:jimjag,项目名称:libdill,代码行数:32,代码来源:prefix.c
示例14: udp_recvl_
ssize_t udp_recvl_(struct msock_vfs *mvfs, struct ipaddr *addr,
struct iolist *first, struct iolist *last, int64_t deadline) {
struct udp_sock *obj = dill_cont(mvfs, struct udp_sock, mvfs);
struct msghdr hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.msg_name = (void*)addr;
hdr.msg_namelen = sizeof(struct ipaddr);
/* Make a local iovec array. */
/* TODO: This is dangerous, it may cause stack overflow.
There should probably be a on-heap per-socket buffer for that. */
size_t niov;
int rc = iol_check(first, last, &niov, NULL);
if(dill_slow(rc < 0)) return -1;
struct iovec iov[niov];
iol_toiov(first, iov);
hdr.msg_iov = (struct iovec*)iov;
hdr.msg_iovlen = niov;
while(1) {
ssize_t sz = recvmsg(obj->fd, &hdr, 0);
if(sz >= 0) return sz;
if(errno != EAGAIN && errno != EWOULDBLOCK) return -1;
rc = fdin(obj->fd, deadline);
if(dill_slow(rc < 0)) return -1;
}
}
开发者ID:reqshark,项目名称:libdill,代码行数:25,代码来源:udp.c
示例15: dill_term_mrecvl
static ssize_t dill_term_mrecvl(struct dill_msock_vfs *mvfs,
struct dill_iolist *first, struct dill_iolist *last, int64_t deadline) {
struct dill_term_sock *self = dill_cont(mvfs, struct dill_term_sock, mvfs);
if(self->len == 0) {
ssize_t sz = dill_mrecvl(self->u, first, last, deadline);
if(dill_slow(sz < 0)) return -1;
if(dill_slow(sz == 0)) {
self->indone = 1;
errno = EPIPE;
return -1;
}
return sz;
}
struct dill_iolist trimmed = {0};
int rc = dill_ioltrim(first, self->len, &trimmed);
uint8_t buf[self->len];
struct dill_iolist iol = {buf, self->len, rc < 0 ? NULL : &trimmed, 0};
ssize_t sz = dill_mrecvl(self->u, &iol, rc < 0 ? &iol : last, deadline);
if(dill_slow(sz < 0)) return -1;
if(dill_slow(sz == self->len &&
dill_slow(memcmp(self->buf, buf, self->len) == 0))) {
self->indone = 1;
errno = EPIPE;
return -1;
}
dill_iolto(buf, self->len, first);
return sz;
}
开发者ID:jimjag,项目名称:libdill,代码行数:28,代码来源:term.c
示例16: sf_finish
static int sf_finish(int s, int64_t deadline) {
int u = sfdetach(s, deadline);
if(dill_slow(u < 0)) return -1;
int rc = hfinish(u, deadline);
if(dill_slow(rc != 0)) return -1;
return 0;
}
开发者ID:ConfusedReality,项目名称:pkg_websocket_dillsocks,代码行数:7,代码来源:sf.c
示例17: dill_term_done
int dill_term_done(int s, int64_t deadline) {
struct dill_term_sock *self = dill_hquery(s, dill_term_type);
if(dill_slow(!self)) return -1;
if(dill_slow(self->outdone)) {errno = EPIPE; return -1;}
int rc = dill_msend(self->u, self->buf, self->len, deadline);
if(dill_slow(rc < 0)) return -1;
self->outdone = 1;
return 0;
}
开发者ID:jimjag,项目名称:libdill,代码行数:9,代码来源:term.c
示例18: mrecvl
ssize_t mrecvl(int s, struct iolist *first, struct iolist *last,
int64_t deadline) {
struct msock_vfs *m = hquery(s, msock_type);
if(dill_slow(!m)) return -1;
if(dill_slow((last && last->iol_next) ||
(!first && last) ||
(first && !last))) {
errno = EINVAL; return -1;}
return m->mrecvl(m, first, last, deadline);
}
开发者ID:reqshark,项目名称:libdill,代码行数:10,代码来源:msock.c
示例19: dill_msleep
int dill_msleep(int64_t deadline) {
/* Return ECANCELED if shutting down. */
int rc = dill_canblock();
if(dill_slow(rc < 0)) return -1;
/* Actual waiting. */
struct dill_tmclause tmcl;
dill_timer(&tmcl, 1, deadline);
int id = dill_wait();
if(dill_slow(id < 0)) return -1;
return 0;
}
开发者ID:jimjag,项目名称:libdill,代码行数:11,代码来源:libdill.c
示例20: tcpconn_recv
static int tcpconn_recv(int s, void *buf, size_t len, int64_t deadline) {
struct tcpconn *conn = bsockdata(s, tcpconn_type);
if(dill_slow(!conn)) return -1;
/* If there's enough data in the buffer use it. */
if(dill_fast(len <= conn->ilen)) {
memcpy(buf, conn->ibuf, len);
memmove(conn->ibuf, conn->ibuf + len, conn->ilen - len);
conn->ilen -= len;
return 0;
}
/* If there's not enough data in the buffer, yet the message is small,
read whole chunk of data to avoid excessive system calls. */
if(len <= BATCHSIZE) {
/* First try a non-blocking batch read. */
size_t recvd = BATCHSIZE - conn->ilen;
/* TODO: Make sure that deadline of 0 works as intended! */
dsrecv(conn->fd, conn->ibuf + conn->ilen, &recvd, 0);
conn->ilen += recvd;
if(dill_fast(len <= conn->ilen)) {
memcpy(buf, conn->ibuf, len);
memmove(conn->ibuf, conn->ibuf + len, conn->ilen - len);
conn->ilen -= len;
return 0;
}
}
/* Either message is big or we weren't able to read it in non-blocking
fashion. In both cases let's try to read the missing data directly
to the user's buffer. If the operation fails we'll copy the data that
was already read to the input buffer. To make sure that the operation
is atomic even in face of memory shortage let's resize the buffer first
do receiving second. */
if(dill_slow(len > conn->ilen)) {
char *newbuf = realloc(conn->ibuf, len);
if(dill_slow(!newbuf)) {errno = ENOMEM; return -1;}
conn->ibuf = newbuf;
conn->icap = len;
}
/* Read the missing part directly into user's buffer. */
size_t recvd = len - conn->ilen;
int rc = dsrecv(conn->fd, ((char*)buf) + conn->ilen, &recvd, deadline);
/* If succesfull copy the first part of the message from input buffer. */
if(dill_fast(rc == 0)) {
memcpy(buf, conn->ibuf, conn->ilen);
conn->ilen = 0;
return 0;
}
/* If not successful, store the aready received data into input buffer. */
int err = errno;
memcpy(conn->ibuf + conn->ilen, ((char*)buf) + conn->ilen, recvd);
conn->ibuf += recvd;
errno = err;
return -1;
}
开发者ID:ConfusedReality,项目名称:pkg_websocket_dillsocks,代码行数:53,代码来源:tcp.c
注:本文中的dill_slow函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论