本文整理汇总了C++中ACL_VSTREAM_SOCK函数的典型用法代码示例。如果您正苦于以下问题:C++ ACL_VSTREAM_SOCK函数的具体用法?C++ ACL_VSTREAM_SOCK怎么用?C++ ACL_VSTREAM_SOCK使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ACL_VSTREAM_SOCK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __rw_timer_fn
static void __rw_timer_fn(ACL_VSTREAM *stream)
{
char myname[] = "__rw_timer_fn";
if (stream == NULL || ACL_VSTREAM_SOCK(stream) < 0)
acl_msg_fatal("%s(%d)->%s: input error, null stream",
__FILE__, __LINE__, myname);
if (acl_msg_verbose)
acl_msg_info("%s(%d)->%s: rw timeout, fd = %d",
__FILE__, __LINE__, myname,
ACL_VSTREAM_SOCK(stream));
acl_multi_server_disconnect(stream);
}
示例2: ACL_VSTREAM_PEER
const char* socket_stream::get_peer_ip() const
{
if (stream_ == NULL)
return dummy_;
if (peer_ip_[0] != 0)
return peer_ip_;
char* ptr = ACL_VSTREAM_PEER(stream_);
if (ptr == NULL || *ptr == 0)
{
char buf[64];
if (acl_getpeername(ACL_VSTREAM_SOCK(stream_),
buf, sizeof(buf)) == -1)
{
return dummy_;
}
acl_vstream_set_peer(stream_, buf);
}
return const_cast<socket_stream*> (this)->get_ip(
ACL_VSTREAM_PEER(stream_),
const_cast<socket_stream*> (this)->peer_ip_,
sizeof(peer_ip_));
}
示例3: event_enable_write
static void event_enable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream,
int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context)
{
const char *myname = "event_enable_write";
EVENT_POLL_THR *event_thr = (EVENT_POLL_THR *) eventp;
ACL_EVENT_FDTABLE *fdp;
ACL_SOCKET sockfd;
sockfd = ACL_VSTREAM_SOCK(stream);
fdp = (ACL_EVENT_FDTABLE*) stream->fdp;
if (fdp == NULL) {
fdp = event_fdtable_alloc();
fdp->listener = 0;
fdp->stream = stream;
stream->fdp = (void *) fdp;
} else if (fdp->flag & EVENT_FDTABLE_FLAG_READ)
acl_msg_panic("%s(%d)->%s: fd %d: multiple I/O request",
__FILE__, __LINE__, myname, sockfd);
else {
fdp->listener = 0;
fdp->stream = stream;
}
if (fdp->w_callback != callback || fdp->w_context != context) {
fdp->w_callback = callback;
fdp->w_context = context;
}
if (timeout > 0) {
fdp->w_timeout = timeout * 1000000;
fdp->w_ttl = eventp->present + fdp->w_timeout;
} else {
fdp->w_ttl = 0;
fdp->w_timeout = 0;
}
if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE) != 0)
return;
stream->nrefer++;
fdp->flag = EVENT_FDTABLE_FLAG_WRITE | EVENT_FDTABLE_FLAG_EXPT;
THREAD_LOCK(&event_thr->event.tb_mutex);
fdp->fdidx = eventp->fdcnt;
eventp->fdtabs[eventp->fdcnt++] = fdp;
event_thr->fds[fdp->fdidx].fd = sockfd;
event_thr->fds[fdp->fdidx].events = POLLOUT | POLLHUP | POLLERR;
if (eventp->maxfd == ACL_SOCKET_INVALID || eventp->maxfd < sockfd)
eventp->maxfd = sockfd;
acl_fdmap_add(event_thr->fdmap, sockfd, fdp);
THREAD_UNLOCK(&event_thr->event.tb_mutex);
if (event_thr->event.blocked && event_thr->event.evdog
&& event_dog_client(event_thr->event.evdog) != stream)
event_dog_notify(event_thr->event.evdog);
}
示例4: enable_listen
static void enable_listen(EVENT_KERNEL *ev, ACL_EVENT_FDTABLE *fdp)
{
const char *myname = "enable_listen";
ACL_SOCKET sock;
DWORD ReceiveLen = 0;
sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP,
0, 0, WSA_FLAG_OVERLAPPED);
memset(&fdp->event_read->overlapped, 0,
sizeof(fdp->event_read->overlapped));
fdp->stream->type |= ACL_VSTREAM_TYPE_LISTEN_IOCP;
fdp->stream->iocp_sock = sock;
if (AcceptEx(ACL_VSTREAM_SOCK(fdp->stream), sock,
fdp->event_read->myAddrBlock, 0,
ACCEPT_ADDRESS_LENGTH, ACCEPT_ADDRESS_LENGTH,
&ReceiveLen, &fdp->event_read->overlapped) == FALSE
&& acl_last_error() !=ERROR_IO_PENDING)
{
acl_msg_warn("%s(%d): AcceptEx error(%s)",
myname, __LINE__, acl_last_serror());
}
}
示例5: event_enable_read
static void event_enable_read(ACL_EVENT *eventp, ACL_VSTREAM *stream,
int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context)
{
const char *myname = "event_enable_read";
EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp;
ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE *) stream->fdp;
ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream);
if (fdp == NULL) {
fdp = event_fdtable_alloc();
fdp->flag = EVENT_FDTABLE_FLAG_ADD_READ | EVENT_FDTABLE_FLAG_EXPT;
fdp->stream = stream;
acl_ring_append(&ev->fdp_delay_list, &fdp->delay_entry);
fdp->flag |= EVENT_FDTABLE_FLAG_DELAY_OPER;
stream->fdp = (void *) fdp;
/* 添加流关闭时的回调函数 */
acl_vstream_add_close_handle(stream, stream_on_close, eventp);
} else if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_READ)) {
goto END;
} else if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_READ)) {
/* 停止禁止读监听过程 */
acl_assert((fdp->flag & EVENT_FDTABLE_FLAG_READ));
/* 重新启用读监听过程, 因为之前的过程是正在拆除读监听过程但
* 还没有正式拆除,所以只需要清除拆除标志位即可
*/
fdp->flag &= ~EVENT_FDTABLE_FLAG_DEL_READ;
} else if (!(fdp->flag & EVENT_FDTABLE_FLAG_READ)) {
fdp->flag |= EVENT_FDTABLE_FLAG_ADD_READ;
if (!(fdp->flag & EVENT_FDTABLE_FLAG_DELAY_OPER)) {
acl_ring_append(&ev->fdp_delay_list, &fdp->delay_entry);
fdp->flag |= EVENT_FDTABLE_FLAG_DELAY_OPER;
}
}
END:
if (fdp->fdidx == -1) {
fdp->fdidx = eventp->fdcnt;
eventp->fdtabs[eventp->fdcnt++] = fdp;
}
if (eventp->maxfd != ACL_SOCKET_INVALID && eventp->maxfd < sockfd)
eventp->maxfd = sockfd;
if (fdp->r_callback != callback || fdp->r_context != context) {
fdp->r_callback = callback;
fdp->r_context = context;
}
if (timeout > 0) {
fdp->r_timeout = timeout * 1000000;
fdp->r_ttl = eventp->present + fdp->r_timeout;
} else {
fdp->r_ttl = 0;
fdp->r_timeout = 0;
}
}
示例6: acl_assert
int socket_stream::sock_read(void *ctx, unsigned char *buf, size_t len)
{
#ifdef HAS_POLARSSL
socket_stream* cli = (socket_stream*) ctx;
ACL_VSTREAM* stream = cli->get_vstream();
acl_assert(stream);
int ret, timeout = 120;
if ((ret = acl_socket_read(ACL_VSTREAM_SOCK(stream), buf, len,
timeout, stream, NULL)) < 0)
{
int errnum = acl_last_error();
if (ret == ACL_EINTR || ret == ACL_EWOULDBLOCK
#if ACL_EWOULDBLOCK != ACL_EAGAIN
|| ret == ACL_EAGAIN
#endif
)
return POLARSSL_ERR_NET_WANT_READ;
else if (errnum == ACL_ECONNRESET || errno == EPIPE)
return POLARSSL_ERR_NET_CONN_RESET;
else
return POLARSSL_ERR_NET_RECV_FAILED;
}
return ret;
#else
(void) ctx;
(void) buf;
(void) len;
return -1;
#endif
}
示例7: ACL_VSTREAM_LOCAL
const char* socket_stream::get_local_ip() const
{
if (stream_ == NULL)
return dummy_;
// xxx: acl_vstream 中没有对此地址赋值
if (local_ip_[0] != 0)
return local_ip_;
char* ptr = ACL_VSTREAM_LOCAL(stream_);
if (ptr == NULL || *ptr == 0)
{
char buf[256];
if (acl_getsockname(ACL_VSTREAM_SOCK(stream_),
buf, sizeof(buf)) == -1)
{
return dummy_;
}
acl_vstream_set_local(stream_, buf);
}
return const_cast<socket_stream*>(this)->get_ip(
ACL_VSTREAM_LOCAL(stream_),
const_cast<socket_stream*>(this)->local_ip_,
sizeof(local_ip_));
}
示例8: event_enable_read
static void event_enable_read(ACL_EVENT *eventp, ACL_VSTREAM *stream,
int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context)
{
ACL_EVENT_FDTABLE *fdp = read_enable(eventp, stream, timeout,
callback, context);
fdp->listener = acl_is_listening_socket(ACL_VSTREAM_SOCK(stream));
}
示例9: ACL_VSTREAM_SOCK
int polarssl_io::sock_read(void *ctx, unsigned char *buf, size_t len)
{
#ifdef HAS_POLARSSL
polarssl_io* io = (polarssl_io*) ctx;
int ret, timeout = 120;
ACL_VSTREAM* vs = io->stream_->get_vstream();
ACL_SOCKET fd = ACL_VSTREAM_SOCK(vs);
ret = acl_socket_read(fd, buf, len, timeout, vs, NULL);
if (ret < 0)
{
int errnum = acl_last_error();
if (ret == ACL_EINTR || ret == ACL_EWOULDBLOCK
#if ACL_EWOULDBLOCK != ACL_EAGAIN
|| ret == ACL_EAGAIN
#endif
)
return POLARSSL_ERR_NET_WANT_READ;
else if (errnum == ACL_ECONNRESET || errno == EPIPE)
return POLARSSL_ERR_NET_CONN_RESET;
else
return POLARSSL_ERR_NET_RECV_FAILED;
}
return ret;
#else
(void) ctx;
(void) buf;
(void) len;
logger_error("HAS_POLARSSL not defined!");
return -1;
#endif
}
示例10: disable_write
static int disable_write(EVENT_KERNEL *ev, ACL_EVENT_FDTABLE *fdp)
{
const char *myname = "disable_write";
ACL_VSTREAM *stream = fdp->stream;
ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream);
int err, ret = 0;
fdp->flag &= ~EVENT_FDTABLE_FLAG_DEL_WRITE;
fdp->flag &= ~EVENT_FDTABLE_FLAG_WRITE;
fdp->event_type &= ~(ACL_EVENT_WRITE | ACL_EVENT_CONNECT);
if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) {
#if (ACL_EVENTS_KERNEL_STYLE == ACL_EVENTS_STYLE_KQUEUE)
EVENT_REG_DEL_WRITE(err, ev->event_fd, sockfd);
#else
EVENT_REG_MOD_READ(err, ev->event_fd, sockfd, fdp);
#endif
} else {
#ifdef USE_FDMAP
acl_fdmap_del(ev->fdmap, sockfd);
#endif
#ifdef EVENT_REG_DEL_BOTH
EVENT_REG_DEL_BOTH(err, ev->event_fd, sockfd);
#else
EVENT_REG_DEL_WRITE(err, ev->event_fd, sockfd);
#endif
ret = 1;
}
if (err < 0) {
acl_msg_fatal("%s: %s: %s, err(%d), fd(%d), ret(%d)",
myname, EVENT_REG_DEL_TEXT, acl_last_serror(),
err, sockfd, ret);
}
return (ret);
}
示例11: get_vstream
ACL_SOCKET aio_stream::get_socket() const
{
ACL_VSTREAM* stream = get_vstream();
if (stream == NULL)
return ACL_SOCKET_INVALID;
return ACL_VSTREAM_SOCK(stream);
}
示例12: acl_assert
int ssl_aio_stream::__sock_send(void *ctx, const unsigned char *buf, size_t len)
{
#ifdef HAS_POLARSSL
ssl_aio_stream* cli = (ssl_aio_stream*) ctx;
ACL_VSTREAM* stream = cli->get_vstream();
acl_assert(stream);
int ret, errnum;
if ((ret = acl_socket_write(ACL_VSTREAM_SOCK(stream), buf, len,
0, stream, NULL)) < 0)
{
errnum = acl_last_error();
if (errnum == ACL_EINTR)
return POLARSSL_ERR_NET_WANT_WRITE;
else if (errnum == ACL_EWOULDBLOCK)
return POLARSSL_ERR_NET_WANT_WRITE;
#if ACL_EWOULDBLOCK != ACL_EAGAIN
else if (errnum == ACL_EAGAIN)
return POLARSSL_ERR_NET_WANT_WRITE;
#endif
else if (errnum == ACL_ECONNRESET || errno == EPIPE)
return POLARSSL_ERR_NET_CONN_RESET;
else
return POLARSSL_ERR_NET_SEND_FAILED;
}
return ret;
#else
(void) ctx;
(void) buf;
(void) len;
return -1;
#endif
}
示例13: acl_aio_vstream
const char* aio_stream::get_local(bool full /* = false */) const
{
if (stream_ == NULL)
return dummy_;
ACL_VSTREAM* vs = acl_aio_vstream(stream_);
const char* ptr = ACL_VSTREAM_LOCAL(vs);
ACL_SOCKET fd = ACL_VSTREAM_SOCK(vs);
if (ptr == NULL || *ptr == 0)
{
char buf[256];
if (acl_getsockname(fd, buf, sizeof(buf)) == -1)
return dummy_;
acl_vstream_set_local(vs, buf);
}
ptr = ACL_VSTREAM_LOCAL(vs);
if (full)
return ptr;
else if (local_ip_[0] != 0)
return local_ip_;
return const_cast<aio_stream*> (this)->get_ip(ptr,
const_cast<aio_stream*>(this)->local_ip_, sizeof(local_ip_));
}
示例14: enable_write
static void enable_write(EVENT_KERNEL *ev, ACL_EVENT_FDTABLE *fdp)
{
const char *myname = "enable_write";
ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(fdp->stream);
int err;
fdp->flag &= ~EVENT_FDTABLE_FLAG_ADD_WRITE;
fdp->flag |= EVENT_FDTABLE_FLAG_WRITE;
if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) {
#if (ACL_EVENTS_KERNEL_STYLE == ACL_EVENTS_STYLE_KQUEUE)
EVENT_REG_ADD_WRITE(err, ev->event_fd, sockfd, fdp);
#else
EVENT_REG_MOD_RDWR(err, ev->event_fd, sockfd, fdp);
#endif
} else {
EVENT_REG_ADD_WRITE(err, ev->event_fd, sockfd, fdp);
}
if (err < 0) {
acl_msg_fatal("%s: %s: %s, err(%d), fd(%d)",
myname, EVENT_REG_ADD_TEXT,
acl_last_serror(), err, sockfd);
}
}
示例15: vstream_server
static int vstream_server(void)
{
const char *myname = "vstream_server";
ACL_VSTREAM *sstream, *client;
char ebuf[256];
sstream = acl_vstream_listen(addr, 128);
if (sstream == NULL) {
printf("%s(%d): listen on %s error(%s)\r\n",
myname, __LINE__, addr,
acl_last_strerror(ebuf, sizeof(ebuf)));
return (-1);
}
acl_tcp_defer_accept(ACL_VSTREAM_SOCK(sstream), 0);
printf("%s: listen %s ok\r\n", myname, addr);
while (1) {
client = acl_vstream_accept(sstream, NULL, 0);
if (client == NULL) {
printf("%s(%d): accept error(%s)\r\n",
myname, __LINE__,
acl_last_strerror(ebuf, sizeof(ebuf)));
return (-1);
}
printf("accept one\r\n");
if (1)
reply_client2(client);
else
reply_client(client);
acl_vstream_close(client);
}
return (0);
}