Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:24:22+00:00 2026-06-13T18:24:22+00:00

I am using libevent for handling data receipt on a set of ports. The

  • 0

I am using libevent for handling data receipt on a set of ports. The behavior i would like to accomplish is this:

-Say i have a set of ports, 1001-1004
-Read in data on port, say 1001.
-As soon as the callback is hit, disable further reading on this port (1001).
-Once all ports have received data, turn them all back on for reading.

Right now i have a struct of bufferevents:

static struct bufferevent *bev[4];

I set up the listeners like they show in the documentation:

/* Listener 1 */
sin.sin_port = htons(MIXPORT + 1);
listener1 = evconnlistener_new_bind(base, accept1, NULL,
    LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE, -1,
    (struct sockaddr*)&sin, sizeof(sin));
if (!listener1) { perror("Couldn't create listener1"); return 1; }
evconnlistener_set_error_cb(listener1, accept_error_cb);

static void accept1(struct evconnlistener *listener,
evutil_socket_t fd, struct sockaddr *address, int socklen,
void *ctx) {
/* A new connection was received on this port */
struct event_base *base = evconnlistener_get_base(listener);
bev[0] = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);

/* Callback for when (*bufevent, data READ, data WRITTEN, event OCCURRED, *void) */
bufferevent_setcb(bev[0], read1, NULL, echo_event_cb, NULL);

/* Set bufferevent to be able to read */
bufferevent_enable(bev[0], EV_READ);
}

Then i gave it a READ callback:

static void read1(struct bufferevent *bev, void *ctx) {
if(LOG) { logoutput("Data received on port 1"); }

struct evbuffer *input = bufferevent_get_input(bev);
size_t len = evbuffer_get_length(input);
data[0] = malloc(len);

/* Copy evbuffer data into array */
evbuffer_copyout(input, data[0], len);
/* Remove data from evbuffer after copying it out */
evbuffer_drain(input, len);

handle(0);
}  

In my “handle” function, i told it to do this:

static void handle(int i)
{
/* Disable reading on port until re-enabled later */
bufferevent_disable(bev[i], EV_READ);  // I thought this should do it?!

// Do other stuff...
random_function();
}

And finally…

static void random_function(); {
/* Re-enable read on port */
    bufferevent_enable(bev[src], EV_READ);
}

Any ideas what i’m doing wrong? When i sent data to a random port, i am still able to send it more, and more, and more.
TIA!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:24:23+00:00Added an answer on June 13, 2026 at 6:24 pm

    It looks like you are just disabling reading the data on a socket, but this won’t stop someone from sending you data on that socket (The OS will buffer a fair amount of data from them because it assumes that you’ll want to read it when you have time).

    You can’t stop them from sending data, but you can stop new connections to those ports (by not accepting connections on your blocked ports until you want to again), and you can close connections on your closed ports if they do send you data (that would mean that you still want to read on those ports, but if they send you anything, you close() them or something like that.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Jenkins or Hudson I would like to create a pipeline of builds with
Using Rails 3.2.0 with haml and sass: I Would like to link an external
What have I done? I'm using Microsoft Visual Studio 2010 1) I downloaded libevent-2.0.16-stable
Using python-requests and python-magic, I would like to test the mime-type of a web
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
I have been trying to compile systrace (1.6g) on Ubuntu. When I am using
I'm writing an event driven application using the libevent library for asynchronous I/O. Essentially,
Using Android TelephonyManager an application can obtain the state of data activity over the
While compiling my program which is using libevent library I am using gcc option

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.