Tomer Heber | 5 Feb 00:02 2016

RE: Install help on Max OS X

Hi,

 

It seems you are building libevent with openssl support.

You will need to build openssl before using libevent or build libevent without ssl support.

 

10x,

Tomer.

 

From: owner-libevent-users <at> freehaven.net [mailto:owner-libevent-users <at> freehaven.net] On Behalf Of Sumonto Ghosh
Sent: Thursday, February 04, 2016 3:01 PM
To: libevent-users <at> freehaven.net
Subject: [Libevent-users] Install help on Max OS X

 

Hi 

How do I install libevent on Max OS X?

 

Installed openssl as:

./Configure darwin64-x86_64-cc && make install

Installed libevent as:

./config x86_64 && make

 

I get the following error:

Shao Miller | 3 Feb 07:56 2016

EVENT2_MS_CALLING_CONVENTION Macro Suggestion

Hello, libevent mailing-list.

Here[1] are some steps which helped me to build libevent with Microsoft 
Windows XP.

The only quirk I've discovered so far is that when I want to use the 
Windows DDK's "BUILD" program to build a libevent-consuming project, I 
run into calling convention mismatching...  By default, BUILD seems to 
want to give /Gz to the compiler, which specifies __stdcall as the 
default calling convention for functions.  Unfortunately, the steps[1] 
that I used resulted in a libevent DLL using the __cdecl calling 
convention.  The compiler would want /Gd, for that.

So what happens is that only one of these will be linked:
- libevent (via __cdecl)
- Winsock2 (ws2_32, via __stdcall)

In a BUILD "sources" file, one can use the following line to request /Gd:

   386_STDCALL=0

But that doesn't help with Winsock2.

Fortunately, Winsock2's header uses WSAAPI to mark the calling 
convention for its functions.  That preprocesses as "FAR PASCAL", so the 
following ugly hack gets libevent and Winsock2 to play nicely with BUILD:

   #ifndef WIN32
   /* ... */
   #else
   #include <windows.h>
   #define PASCAL __stdcall
   #include <winsock2.h>
   #endif

The build-log will warn about a redefinition of PASCAL, but oh well.

Does anyone think it might be worth-while to introduce an 
EVENT2_MS_CALLING_CONVENTION macro between the return-type and 
identifier for each libevent function?  (That's where Microsoft wants 
it, if I recall correctly.)  Or, if all other implementations use the 
same convention for the location of such a calling-convention extension, 
perhaps EVENT2_CALLING_CONVENTION. Hooray for clutter?

(Another way to ask is, "Would anyone object to...")

[1] https://www.synthetel.com/libevent-xp
--

-- 

Shao Miller
Synthetel Corporation
E: libevent <at> synthetel.com
W: https://www.synthetel.com

***********************************************************************
To unsubscribe, send an e-mail to majordomo <at> freehaven.net with
unsubscribe libevent-users    in the body.

Eax Melanhovich | 2 Feb 06:18 2016
Picon

Comparison of libevent and libuv

Hello.

I apologize for a holy war question. But libevent and libuv look very
similar --- both solve the same issue ("c10k problem"), both support
Windows, etc. And there is a little information regarding _differences_
of these libraries I manage to find by myself. Libevent seems to be
more mature and widely used. Also according to this article:

http://blog.kazuhooku.com/2014/09/the-reasons-why-i-stopped-using-libuv.html

... libuv has some considerable problems, e.g. lack of TLS support.
However this article was written 1.5 years ago and some issues could be
solved already.

I wonder what was the story behind creating libuv while libevent
already existed at that time. What problems libevent had back then (or
probably it didn't?), were these issues solved or not, are there any
major differences between libevent and libuv today, etc?

Hope someone who has experience in this area could enlighten me.
***********************************************************************
To unsubscribe, send an e-mail to majordomo <at> freehaven.net with
unsubscribe libevent-users    in the body.

Picon

Line-based evbuffer?

Hi!

Are there any tricks to make an evbuffer line-based? I would love it if I could read line by line from the evbuffer. Are there any tricks I can do?

-Oystein

girish kumar | 30 Jan 13:38 2016
Picon

close not captured with strace for sockets created using BEV_OPT_CLOSE_ON_FREE

Hi All,

I am new to this mailing list.

I am using a multi threaded sever application using libevent-2.1.4-alpha. As part of it, binding the server to UNIX domain socket and listening for clients.

When accepting connections, creating buffer events with flags enabled with BEV_OPT_CLOSE_ON_FREE.

While debugging few issues with strace, observed that close is not getting called on the accepted client fd, when the client gets disconnected. However sockets are getting freed up, when checking proc entry /proc/pid/fds.

But, when disabled the BEV_OPT_CLOSE_ON_FREE flag and doing explicit close of accepted client fd, things looks as expected i nterms of strace output and proc/pid/fd entries.

Please help in understanding the behavior, your help will be highly appreciated.


--
With Best Regards,
Girish
Picon

Simple client. How to handle login prompts.

Hi!

I'm trying to connect a bot to a server called FIBS. First Internet Backgammon Server. (www.fibs.com) The server is really simple with a plain connection. Try it yourself: telnet fibs.com 4321

After some browsing (and failures), I found out that I need an event handling mechanism and buffered input and output. After some more googling, I found that libevent provides all these features.

However, I'm struggling. I can't find examples nor tutorials to help me. And my experience with events and socket programming is limited.

Here is my current skeleton code:
/* 
 * A simple event driven code for connecting to FIBS. (First Internet Backgammon Server.)
 * More info of fibs: www.fibs.com
 */
#include <event2/dns.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/util.h>
#include <event2/event.h>

#include <stdio.h>
#include <stdlib.h>

void handler (struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg)
{
#if 1
    char buf[1024];
    int n;
    while ((n = evbuffer_remove(buffer, buf, sizeof(buf))) > 0) {
/* handle the message form the server */
        printf( buf );
    }
#else
    size_t len;
    printf(" * ");
    char *request_line;
    request_line = evbuffer_readln(buffer, &len, EVBUFFER_EOL_CRLF);
    if (!request_line) {
    //    printf("No line.\n");
        /* The first line has not arrived yet. */
    } else {
        printf("%s\n", request_line);
        free(request_line);
    }
#endif 
}

void readcb(struct bufferevent *bev, void *ptr)
{
    printf("Read callback.\n");
}

void writecb(struct bufferevent *bev, void *ptr)
{
    printf("Write callback.\n");
}

/* Code taken from http example */
void eventcb(struct bufferevent *bev, short events, void *ptr)
{
    if (events & BEV_EVENT_CONNECTED) {
         printf("Connect okay.\n");
    } else if (events & (BEV_EVENT_ERROR|BEV_EVENT_EOF)) {
         struct event_base *base = ptr;
         if (events & BEV_EVENT_ERROR) {
                 int err = bufferevent_socket_get_dns_error(bev);
                 if (err)
                         printf("DNS error: %s\n", evutil_gai_strerror(err));
         }
         printf("Closing\n");
         bufferevent_free(bev);
         event_base_loopexit(base, NULL);
    }
}

#define FIBS_HOST "fibs.com"
#define FIBS_PORT 4321

int main(int argc, char **argv)
{
    struct event_base *base;
    struct evdns_base *dns_base;
    struct bufferevent *bev;

    base = event_base_new();
    dns_base = evdns_base_new(base, 1);

    bev = bufferevent_socket_new(base, -1, BEV_OPT_CLOSE_ON_FREE);
    bufferevent_setcb(bev, readcb, writecb, eventcb, base);
    bufferevent_enable(bev, EV_READ|EV_WRITE);
    bufferevent_socket_connect_hostname( bev, dns_base, AF_UNSPEC, FIBS_HOST, FIBS_PORT);

    /* Add callback to the evbuffer. (input buffer) */
    struct evbuffer *input = bufferevent_get_input(bev);
    evbuffer_add_cb( input, handler, NULL );

    event_base_dispatch(base);
    return 0;
}

Here comes all my questions:
* Am I on the right track?
* The login prompt from the server does not send a newline, so the handle is not called. How can I find the login prompt?
* I also try to read the lines in the handle callback evbuffer_readln(), but the lines will then bre printed in the wrong order. Why?

Thanks for any input?
-Øystein
Dmitry Chichkov | 15 Jan 17:55 2016
Picon
Gravatar

How to handle large uploads in the evhttp based server?

I'm writing a service using libevent 2.1.5 (beta) that needs to support relatively large (5-10GB) PUT requests (uploads) over local 10GB ethernet.
It'd be ideal if I could handle these in a chunked mode, just like when the client handles chunked replies, rather than consume memory or split it into zillions of small HTTP requests...

Along these lines (server side):
   evhttp_accept_socket(http, nfd);
   evhttp_set_cb(http, "/upload", http_upload, base);
  
   static void http_upload(struct evhttp_request *req, void *arg) {
      if (evhttp_request_get_command(req) == EVHTTP_REQ_POST) {
          evhttp_request set_chunked_cb(req, http_upload_chunk);
      }
   }

  static void  http_upload_chunk(..)  {handle uploaded chunk of data}

  
I'm trying to do it, but  evhttp_request set_chunked_cb   just complains it is in the client mode.
Is that by design?  Just not implemented?  Am I doing something wrong?


Cheers,
Dmitry
Christian Stieber | 15 Jan 12:37 2016
Picon

evconnlistener blocks "other stuff"

I recently looked into the problem that spamming my server with
connections would even prevent it from responding to the CTRL-C signal.
First thing I did was to add priorities to my events, with signals getting
the highest and sockets getting the lowest prio. Much to my surprise, that
didn't change anything at all.

After some headscratching, and since I'm using EVLOOP_ONCE anyway to
implement a delayed disposal of objects, I threw some
event_base_loopbreak() calls into the code to see if that would help.
Again, it still didn't get my Ctrl-C until I stopped spamming connections
at the server.

More reading got me to the "complicated event base", and the
event_config_set_max_dispatch_interval() option. Needless to say, it
didn't improve things.

I was already concerned that the evconnlistener didn't support priorities,
but even at default priority it should be lower than the signal priority
as I have 4 priority levels. So, I started to dig into the libevent code
itself.

Turns out, the evconnlistener (listener.c) accepts connections until it
gets an error, apparently (I can't say I went through all the libevent
code)
without checking for things like event_config_set_max_dispatch_interval.
My build now applies a patch to the libevent build that just breaks the
loop after 10 accepts, and that finally got my signals noticed.

I've attached the patch for purely informal reasons; a real change should
not break the loop after 10 tries but use the parameters that libevent
already has. For now, I just needed something that works, and doesn't
require me to spend days researching how libevent is supposed to work
internally.
*** listener.c	2015-01-05 14:54:34.000000000 +0100
--- listener.c	2016-01-15 10:03:38.103375674 +0100
***************
*** 390,399 ****
--- 390,400 ----
  	struct evconnlistener *lev = p;
  	int err;
  	evconnlistener_cb cb;
  	evconnlistener_errorcb errorcb;
  	void *user_data;
+ 	int count=0;
  	LOCK(lev);
  	while (1) {
  		struct sockaddr_storage ss;
  		ev_socklen_t socklen = sizeof(ss);
  		evutil_socket_t new_fd = evutil_accept4_(fd, (struct sockaddr*)&ss, &socklen, lev->accept4_flags);
***************
*** 422,431 ****
--- 423,437 ----
  			int freed = listener_decref_and_unlock(lev);
  			EVUTIL_ASSERT(freed);
  			return;
  		}
  		--lev-≥refcnt;
+ 		if (++count==10)
+ 		{
+ 			UNLOCK(lev);
+ 			return;
+ 		}
  	}
  	err = evutil_socket_geterror(fd);
  	if (EVUTIL_ERR_ACCEPT_RETRIABLE(err)) {
  		UNLOCK(lev);
  		return;
Anand Raj Manickam | 11 Dec 16:52 2015
Picon

Libevent Schedule Mechanism /Performance

Hi ,
I have a 8 core machine , with 8 threads which have registered with
libevent for accept callbacks.
All it does it accept a connection and close the connection from the thread.
I could see that performance could scale linearly with cpu utilization
till 4 threads , if i spawn more threads the performance does not
increase and also the CPU utilization remains less than 500%.
For a single thread - i get 30k req/per sec - cpu utilization - 99%
2 threads- 40k -198%
4 threads - 60k - 390%
8 threads - 60k - 500-650 %

Can someone shed some light on this behavior ?
How is the scheduling done by libevent when the accepts happen ?
Is there any reference on the libevent code i could tweak ?

I m using this on Linux Platform using pthreads .
***********************************************************************
To unsubscribe, send an e-mail to majordomo <at> freehaven.net with
unsubscribe libevent-users    in the body.

Anty Rao | 1 Dec 10:11 2015
Picon

Fwd: Welcome to libevent-users

hi all

Using libevent-openssl(libevent-2.0.22-stable) library to interact with Apple's APNS server, I observe that response from APNS server sometimes is missing.from the result of tcpdump, it seems the response is did send to me,and there is a RST package come next.however, libevent-openssl only detect the TCP connection is broken,not aware of data is pending for read. So i was wondering if this is TCP-related problem : receiver buffer is discarded when receiving RST. Or it's the problem with the openssl library. Can someone shed some light on me, Thanks. following is the result of tcpdump when response can't be read.

22:29:52.284797 IP 17.143.162.202.2195 > xx.xx.xx.xx.49038: Flags [FP.], seq 4801:4838, ack 4158, win 340, option s [nop,nop,TS val 1184022887 ecr 2339879379], length 37 0x0000: 4500 0059 dcdb 4000 2e06 021a 118f a2ca E..Y.. <at> ......... 0x0010: b73c 0214 0893 bf8e 93b8 7466 2b1b 88c2 .<........tf+... 0x0020: 8019 0154 faed 0000 0101 080a 4692 c167 ...T........F..g 0x0030: 8b77 b9d3 1503 0100 2006 f287 45d4 311e .w..........E.1. 0x0040: e3fe 5cfc 9904 b7a6 2e7e 1221 9967 fdd3 ..\......~.!.g.. 0x0050: 5314 a007 f48d 7490 d6 S.....t.. 22:29:52.284802 IP xx.xx.xx.xx.49038 > 17.143.162.202.2195: Flags [.], ack 4764, win 15, options [nop,nop,TS val 2339879429 ecr 1184022886,nop,nop,sack 1 {4801:4839}], length 0 0x0000: 4500 0040 c041 4000 4006 0ccd b73c 0214 E.. <at> .A <at> . <at> ....<.. 0x0010: 118f a2ca bf8e 0893 2b1b cca2 93b8 7441 ........+.....tA 0x0020: b010 000f ad39 0000 0101 080a 8b77 ba05 .....9.......w.. 0x0030: 4692 c166 0101 050a 93b8 7466 93b8 748c F..f......tf..t. 22:29:52.483487 IP 17.143.162.202.2195 > xx.xx.xx.xx.49038: Flags [R], seq 2478339137, win 0, length 0 0x0000: 4500 0028 0000 4000 2e06 df26 118f a2ca E..(.. <at> ....&.... 0x0010: b73c 0214 0893 bf8e 93b8 7441 0000 0000 .<........tA.... 0x0020: 5004 0000 721b 0000 0000 0000 0000 P...r......... ------------------------------------------------------------------------------------ another : 16:18:00.168274 IP 17.143.161.207.2195 > xx.xxx.xx.xx.43361: Flags [P.], seq 4764:4801, ack 37462, win 432, option s [nop,nop,TS val 1248125705 ecr 2355901348], length 37 0x0000: 4500 0059 c936 4000 3006 14ba 118f a1cf E..Y.6 <at> .0....... 0x0010: b73c 0214 0893 a961 1e10 133f 2197 3724 .<.....a...?!.7$ 0x0020: 8018 01b0 245e 0000 0101 080a 4a64 e309 ....$^......Jd.. 0x0030: 8c6c 33a4 1503 0100 2012 a99f e30c 37aa .l3...........7. 0x0040: eda1 e24a 1819 74cb 1a73 2396 f76e b9fa ...J..t..s#..n.. 0x0050: 293b 8625 8a9d 09a7 30 );.%....0 16:18:00.168326 IP 17.143.161.207.2195 > xx.xxx.xx.xx.43361: Flags [R.], seq 4801, ack 37462, win 498, options [no p,nop,TS val 1248125705 ecr 2355901348], length 0 0x0000: 4500 0034 c937 4000 3006 14de 118f a1cf E..4.7 <at> .0....... 0x0010: b73c 0214 0893 a961 1e10 1364 2197 3724 .<.....a...d!.7$ 0x0020: 8014 01f2 de75 0000 0101 080a 4a64 e309 .....u......Jd.. 0x0030: 8c6c 33a4 .l3.
-- 
Anty Rao
Kaushal Shriyan | 13 Nov 14:30 2015
Picon

libevent2 repo or rpm binaries for CentOS 6.x

Hi,

Do i need to enable any repo on CentOS 6.x to install libevent2 or any rpm binary packages?

Regards,

Kaushal

Gmane