本文整理汇总了C++中EVBUFFER_LENGTH函数的典型用法代码示例。如果您正苦于以下问题:C++ EVBUFFER_LENGTH函数的具体用法?C++ EVBUFFER_LENGTH怎么用?C++ EVBUFFER_LENGTH使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVBUFFER_LENGTH函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: input_ground
/* Reset for ground state. */
void
input_ground(struct input_ctx *ictx)
{
evbuffer_drain(ictx->since_ground, EVBUFFER_LENGTH(ictx->since_ground));
if (ictx->input_space > INPUT_BUF_START) {
ictx->input_space = INPUT_BUF_START;
ictx->input_buf = xrealloc(ictx->input_buf, INPUT_BUF_START);
}
}
示例2: evtag_marshal_msg
void
evtag_marshal_msg(struct evbuffer *evbuf, ev_uint32_t tag, const struct msg *msg)
{
struct evbuffer *_buf = evbuffer_new();
assert(_buf != NULL);
evbuffer_drain(_buf, -1);
msg_marshal(_buf, msg);
evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), EVBUFFER_LENGTH(_buf));
evbuffer_free(_buf);
}
示例3: tr_peerIoWriteBuf
void
tr_peerIoWriteBuf( tr_peerIo * io,
struct evbuffer * buf,
tr_bool isPieceData )
{
/* FIXME(libevent2): loop through calls to evbuffer_get_contiguous_space() + evbuffer_drain() */
const size_t n = EVBUFFER_LENGTH( buf );
tr_peerIoWrite( io, EVBUFFER_DATA( buf ), n, isPieceData );
evbuffer_drain( buf, n );
}
示例4: auto_event_error
static void auto_event_error(struct bufferevent *buffev, short what, void *_arg)
{
redsocks_client *client = _arg;
autoproxy_client * aclient = (void*)(client + 1) + client->instance->relay_ss->payload_len;
int saved_errno = errno;
assert(buffev == client->relay || buffev == client->client);
redsocks_touch_client(client);
redsocks_log_errno(client, LOG_DEBUG, "%s errno(%d), State: %d, what: " event_fmt_str,
buffev == client->client?"client":"relay",
saved_errno, aclient->state, event_fmt(what));
if (buffev == client->relay)
{
if ( aclient->state == AUTOPROXY_NEW
&& what == (EVBUFFER_WRITE|EVBUFFER_TIMEOUT))
{
on_connection_blocked(client);
/* In case timeout occurs while connecting relay, we try to connect
to target via SOCKS5 proxy. It is possible that the connection to
target can be set up a bit longer than the timeout value we set.
However, it is still better to make connection via proxy. */
auto_retry(client, 1);
return;
}
if (aclient->state == AUTOPROXY_NEW && saved_errno == ECONNRESET)
if (!auto_retry_or_drop(client))
return;
if (aclient->state == AUTOPROXY_CONNECTED && what == (EVBUFFER_READ|EVBUFFER_ERROR)
&& saved_errno == ECONNRESET )
{
if (!auto_retry_or_drop(client))
return;
}
}
if (what == (EVBUFFER_READ|EVBUFFER_EOF)) {
struct bufferevent *antiev;
if (buffev == client->relay)
antiev = client->client;
else
antiev = client->relay;
redsocks_shutdown(client, buffev, SHUT_RD);
if (antiev != NULL && EVBUFFER_LENGTH(antiev->output) == 0)
redsocks_shutdown(client, antiev, SHUT_WR);
}
else {
redsocks_drop_client(client);
}
}
示例5: relay_dns_request
int
relay_dns_request(struct rsession *con)
{
struct relay *rlay = con->se_relay;
struct relay_dns_priv *priv = con->se_priv;
u_int8_t *buf = EVBUFFER_DATA(con->se_out.output);
size_t len = EVBUFFER_LENGTH(con->se_out.output);
struct relay_dnshdr *hdr;
socklen_t slen;
if (buf == NULL || priv == NULL || len < 1)
return (-1);
if (debug)
relay_dns_log(con, buf, len);
getmonotime(&con->se_tv_start);
if (!TAILQ_EMPTY(&rlay->rl_tables)) {
if (relay_from_table(con) != 0)
return (-1);
} else if (con->se_out.ss.ss_family == AF_UNSPEC) {
bcopy(&rlay->rl_conf.dstss, &con->se_out.ss,
sizeof(con->se_out.ss));
con->se_out.port = rlay->rl_conf.dstport;
}
if ((con->se_out.s = relay_udp_socket(&con->se_out.ss,
con->se_out.port, rlay->rl_proto)) == -1)
return (-1);
slen = con->se_out.ss.ss_len;
hdr = (struct relay_dnshdr *)buf;
hdr->dns_id = htons(priv->dp_inkey);
retry:
if (sendto(con->se_out.s, buf, len, 0,
(struct sockaddr *)&con->se_out.ss, slen) == -1) {
if (con->se_retry) {
con->se_retry--;
log_debug("%s: session %d: "
"forward failed: %s, %s", __func__,
con->se_id, strerror(errno),
con->se_retry ? "next retry" : "last retry");
goto retry;
}
log_debug("%s: session %d: forward failed: %s", __func__,
con->se_id, strerror(errno));
return (-1);
}
event_again(&con->se_ev, con->se_out.s, EV_TIMEOUT|EV_READ,
relay_udp_response, &con->se_tv_start, &env->sc_timeout, con);
return (0);
}
示例6: format_window_pane_tabs
/* Add window pane tabs. */
void
format_window_pane_tabs(struct format_tree *ft, struct window_pane *wp)
{
struct evbuffer *buffer;
u_int i;
buffer = evbuffer_new();
for (i = 0; i < wp->base.grid->sx; i++) {
if (!bit_test(wp->base.tabs, i))
continue;
if (EVBUFFER_LENGTH(buffer) > 0)
evbuffer_add(buffer, ",", 1);
evbuffer_add_printf(buffer, "%d", i);
}
format_add(ft, "pane_tabs", "%.*s", (int) EVBUFFER_LENGTH(buffer),
EVBUFFER_DATA(buffer));
evbuffer_free(buffer);
}
示例7: on_client_read_stream
static void on_client_read_stream(struct bufferevent *bev, void *ctx)
{
Client *cl = ctx;
size_t bytes = EVBUFFER_LENGTH(EVBUFFER_INPUT(bev));
char *buffer = EVBUFFER_DATA(EVBUFFER_INPUT(bev));
prcl_trace(cl, "received %d bytes from client", bytes);
bufferevent_write(cl->server.bufev, buffer, bytes);
evbuffer_drain(EVBUFFER_INPUT(bev), bytes);
}
示例8: cob_
void TEvhttpClientChannel::finish(struct evhttp_request* req) {
if (req == NULL) {
return cob_();
} else if (req->response_code != 200) {
return cob_();
}
recvBuf_->resetBuffer(
EVBUFFER_DATA(req->input_buffer),
EVBUFFER_LENGTH(req->input_buffer));
return cob_();
}
示例9: direct_relay_readcb_helper
static void direct_relay_readcb_helper(redsocks_client *client, struct bufferevent *from, struct bufferevent *to)
{
if (EVBUFFER_LENGTH(to->output) < to->wm_write.high) {
if (bufferevent_write_buffer(to, from->input) == -1)
redsocks_log_errno(client, LOG_ERR, "bufferevent_write_buffer");
}
else {
if (bufferevent_disable(from, EV_READ) == -1)
redsocks_log_errno(client, LOG_ERR, "bufferevent_disable");
}
}
示例10: assert
const void *LibEventTransport::getPostData(int &size) {
if (m_sendEnded) {
size = 0;
return 0;
}
evbuffer *buf = m_request->input_buffer;
assert(buf);
size = EVBUFFER_LENGTH(buf);
return EVBUFFER_DATA(buf);
}
示例11: copy_evbuffer
/* copy event buffer from source to destination as much as possible.
* If parameter skip is not zero, copy will start from the number of skip bytes.
*/
size_t copy_evbuffer(struct bufferevent * dst, const struct bufferevent * src, size_t skip)
{
int n, i;
size_t written = 0;
struct evbuffer_iovec *v;
struct evbuffer_iovec quick_v[5];/* a vector with 5 elements is usually enough */
size_t maxlen = dst->wm_write.high - EVBUFFER_LENGTH(dst->output);
maxlen = EVBUFFER_LENGTH(src->input) - skip> maxlen?maxlen: EVBUFFER_LENGTH(src->input)-skip;
n = evbuffer_peek(src->input, maxlen+skip, NULL, NULL, 0);
if (n>sizeof(quick_v)/sizeof(struct evbuffer_iovec))
v = malloc(sizeof(struct evbuffer_iovec)*n);
else
v = quick_v;
n = evbuffer_peek(src->input, maxlen+skip, NULL, v, n);
for (i=0; i<n; ++i) {
size_t len = v[i].iov_len;
if (skip >= len)
{
skip -= len;
continue;
}
else
{
len -= skip;
}
if (written + len > maxlen)
len = maxlen - written;
if (bufferevent_write(dst, v[i].iov_base+skip, len))
break;
skip = 0;
/* We keep track of the bytes written separately; if we don't,
* we may write more than we need if the last chunk puts
* us over the limit. */
written += len;
}
if (n>sizeof(quick_v)/sizeof(struct evbuffer_iovec))
free(v);
return written;
}
示例12: event_base_free
const void *LibEventTransport::getMorePostData(int &size) {
#ifdef EVHTTP_PORTABLE_READ_LIMITING
if (m_request->ntoread == 0) {
if (m_eventBasePostData != nullptr) {
event_base_free(m_eventBasePostData);
m_eventBasePostData = nullptr;
}
size = 0;
return nullptr;
}
evbuffer *buf = m_request->input_buffer;
assert(buf);
evbuffer_drain(buf, EVBUFFER_LENGTH(buf));
if (evhttp_get_more_post_data(m_request, &m_eventBasePostData,
&m_moreDataRead)) {
buf = m_request->input_buffer;
assert(buf);
size = EVBUFFER_LENGTH(buf);
if (m_request->ntoread == 0) {
if (m_eventBasePostData != nullptr) {
event_base_free(m_eventBasePostData);
m_eventBasePostData = nullptr;
}
evhttp_get_post_data_done(m_request);
}
return EVBUFFER_DATA(buf);
}
if (m_eventBasePostData != nullptr) {
event_base_free(m_eventBasePostData);
m_eventBasePostData = nullptr;
}
evhttp_get_post_data_done(m_request);
size = 0;
return nullptr;
#else
size = 0;
return nullptr;
#endif
}
示例13: webResponseFunc
static void
webResponseFunc( tr_session * session,
long response_code,
const void * response,
size_t response_byte_count,
void * vw )
{
tr_webseed * w = vw;
tr_torrent * tor = tr_torrentFindFromHash( session, w->hash );
const int success = ( response_code == 206 );
/*fprintf( stderr, "server responded with code %ld and %lu bytes\n",
response_code, (unsigned long)response_byte_count );*/
if( !success )
{
/* FIXME */
}
else if( tor != NULL )
{
evbuffer_add( w->content, response, response_byte_count );
if( !w->dead )
{
fireClientGotData( w, response_byte_count );
tr_rcTransferred( &w->rateDown, response_byte_count );
}
if( EVBUFFER_LENGTH( w->content ) < w->byteCount )
requestNextChunk( w );
else {
tr_ioWrite( tor, w->pieceIndex, w->pieceOffset, w->byteCount, EVBUFFER_DATA(w->content) );
evbuffer_drain( w->content, EVBUFFER_LENGTH( w->content ) );
w->busy = 0;
if( w->dead )
tr_webseedFree( w );
else {
fireClientGotBlock( w, w->pieceIndex, w->pieceOffset, w->byteCount );
fireNeedReq( w );
}
}
}
}
示例14: cmd_run_shell_callback
void
cmd_run_shell_callback(struct job *job)
{
struct cmd_run_shell_data *cdata = job->data;
struct cmd_ctx *ctx = &cdata->ctx;
char *cmd, *msg, *line;
size_t size;
int retcode;
u_int lines;
if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)
return;
if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)
return;
lines = 0;
do {
if ((line = evbuffer_readline(job->event->input)) != NULL) {
ctx->print(ctx, "%s", line);
lines++;
}
} while (line != NULL);
size = EVBUFFER_LENGTH(job->event->input);
if (size != 0) {
line = xmalloc(size + 1);
memcpy(line, EVBUFFER_DATA(job->event->input), size);
line[size] = '\0';
ctx->print(ctx, "%s", line);
lines++;
xfree(line);
}
cmd = cdata->cmd;
msg = NULL;
if (WIFEXITED(job->status)) {
if ((retcode = WEXITSTATUS(job->status)) != 0)
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
} else if (WIFSIGNALED(job->status)) {
retcode = WTERMSIG(job->status);
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
}
if (msg != NULL) {
if (lines != 0)
ctx->print(ctx, "%s", msg);
else
ctx->info(ctx, "%s", msg);
xfree(msg);
}
}
示例15: m_server
LibEventTransport::LibEventTransport(LibEventServer *server,
evhttp_request *request,
int workerId)
: m_server(server), m_request(request), m_eventBasePostData(nullptr),
m_workerId(workerId), m_sendStarted(false), m_sendEnded(false) {
// HttpProtocol::PrepareSystemVariables needs this
evbuffer *buf = m_request->input_buffer;
assert(buf);
m_requestSize = EVBUFFER_LENGTH(buf);
m_remote_host = m_request->remote_host;
m_remote_port = m_request->remote_port;
{
char buf[6];
snprintf(buf, 6, "%d.%d", m_request->major, m_request->minor);
m_http_version = buf;
}
switch (m_request->type) {
case EVHTTP_REQ_GET:
m_method = Transport::Method::GET;
m_requestSize += 3;
break;
case EVHTTP_REQ_POST:
m_method = Transport::Method::POST;
m_requestSize += 4;
break;
case EVHTTP_REQ_HEAD:
m_method = Transport::Method::HEAD;
m_requestSize += 4;
break;
default:
assert(false);
m_method = Transport::Method::Unknown;
break;
}
m_extended_method = m_request->ext_method;
assert(m_request->input_headers);
for (evkeyval *p = ((m_evkeyvalq*)m_request->input_headers)->tqh_first; p;
p = p->next.tqe_next) {
if (p->key && p->value) {
m_requestHeaders[p->key].push_back(p->value);
//key, value, ": " and CR/LF
m_requestSize += strlen(p->key) + strlen(p->value) + 4;
}
}
m_url = m_request->uri;
m_requestSize += m_url.size();
m_requestSize += m_http_version.size(); //version number in "HTTP/x.y"
m_requestSize += 11; // HTTP/=5, 2 spaces for url, and CR/LF x2 (first+last)
}