[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] sending data with libevent works just sometimes
- To: Libevent-users@xxxxxxxx
- Subject: [Libevent-users] sending data with libevent works just sometimes
- From: andre <andreapfel@xxxxxxxxx>
- Date: Mon, 06 Jan 2014 23:19:15 +0100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: Libevent-users@xxxxxxxx
- Delivery-date: Mon, 06 Jan 2014 17:19:26 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=S82xOp57vkScrzr+M7RqjNYqfXgbB94zaB0wr5FH6Dg=; b=a6OLx9eRtxpuhuiK+IIT1k5MzYlEC3dbhra6D0tfdPNuBD6D8+ZMw6bCgAVaNWqcKb JQ86p1SN7saEvf0eIDZWHYD3Xikd7j3nS+GbGkedsDpqvdUxvW6ZSukDjKIhoXljnFIi OB1zOBRNcG9wV1XkitVe855mXqSQ8+u/TZwJHg1XgtP1xndDAkQBvoNJO7OQgRjOU5Xi x2tIlZg6ZnyRzUWIxK5GnFvrxKeTqe2t09xctaOXgHRmD92rfyF6cMKj/BUyWlN7ZM8y apxOIDzm5EZFlbkh+XJitEbKbdCIjBLYi7pOyw5OGHd7tLqE2IWSeGcM1pIWK0r4td9G HYLg==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
Hi
I am very new to libevent and even to mailing lists (creating this
thread is probably the 20th try; I found no documentation on that; even
the help-command does not describe anything directly). Please be patient
if I don't describe my problem that well.
I post this question on stackoverflow before I knew this mailing list
but I think that the mailing list is the better option to get support
for libevent.
I am using libevent-2.1.3-alpha that I have compiled on my own because I
needed the pretty new function evbuffer_copyout_from (to get to this
point it took hours, but thats another story). Also I am using the
bufferevent for my programs.
While developing it's very common that things work or they don't (at
least for the present). My test program sends data to my server:
int main(int argc, char **argv)
{
// init stuff
// connect to server
sendPacket(bev);
return 0;
}
Running this program from terminal, it sends the data or not. So it does
not work every time but in most cases it does. I am guessing that
probably the kernel don't send the buffer it has stored. Anyways, there
have to be a method to work around this behavior, because I have to send
this package before I send another one given that the server responses
with a package that I have to proceed before.
My client have a GUI and it have to communicate with a server. Because
threads don't work as I want them to, I decided to use "event_base_loop"
so that it just blocks until one package is processed. After that it can
do GUI stuff so that the window won't freeze. And this simple could be
the while-loop of my program.
I am very certain that my sending fails and NOT my reading because my
server does not call the my callback for reading ("readcb").
I researched a lot about this, but I don't find anything. For example
bufferevent_flush(bev, EV_WRITE, BEV_FLUSH) don't works with sockets (i
tried it even out).
My current function for writing (in short form and simplified for one
package):
void sendPacket(bufferevent * bev)
{
// just data:
const unsigned int msg_ = 12;
char msg[msg_] = "01234567891";
// send that packet:
uint16_t packet_id = 1
bufferevent_write(bev, &packet_id, 2);
bufferevent_write(bev, msg, msg_);
//and this part SHOULD make that data really send but it does not
every time:
while (evbuffer_get_length(bufferevent_get_output(bev)) > 0)
{
event_base_loop(bufferevent_get_base(bev), EVLOOP_ONCE);
};
//this last one, only to be really sure (that's why i use the
second option):
event_base_loop(bufferevent_get_base(bev), EVLOOP_NONBLOCK |
EVLOOP_ONCE);
}
Thanks for your time, I would be lost without your help.
Regards, Andre
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.