[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Read callback problem
- To: libevent-users@xxxxxxxxxxxxx
- Subject: Re: [Libevent-users] Read callback problem
- From: Gordiychuck Oleg <mybrokenbeat@xxxxxxxxx>
- Date: Mon, 7 Feb 2011 12:37:00 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Mon, 07 Feb 2011 05:37:09 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:content-type:mime-version:subject:from :in-reply-to:date:content-transfer-encoding:message-id:references:to :x-mailer; bh=RR7QK6wI0v9H3nQF+loboApL7auIAIq19GQ3DfKJqzc=; b=O+iHxl/kFjC+bW6FWR5On9pL+hkptPyJWGtvcFk54PF2P+mn66YUSIAWp1WSm6XYiG 84KlNgKU9n4Uyayi0xVWQDPa0OG+4GjYY+culCRFPvKxtKWTFOnxkLK8HLjx5dt4Fn+K QHWIAdc5ps8/yC2DlcIrso4Yenx7/r2+2sNIM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=bWwXQSffyeu6fumduNhOZ+PAOIu+U4jqti2sJUoNnXilfTC9/oLWcO9ph2LFg/6f+r 5QPrMNTbLVswawFc+0f+BeQRGR+4/oR6R/d3V6SpIi/bOCSPNzp2doNSHGyJIPF/H2dT lg5mv2VnId1anRW1lVcKp/NALT6Ua18ORFTk4=
- In-reply-to: <BD1F64C7CBB54FAFA1FADA58D76B0FEC@Office>
- References: <BD1F64C7CBB54FAFA1FADA58D76B0FEC@Office>
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
Hello! My send function is next:
static void WriteNeighbor(Neighbor *neighbor, unsigned int size, uint8_t *data)
{
uint8_t pre_data[4];
Utils::put_be32(pre_data, command);
if (bufferevent_write(neighbor->bev,pre_data,4)==-1)
ErrorFactory::Die(Errors::WriteNeighborPreDataError);
if (bufferevent_write(neighbor->bev,data,size) ==-1)
ErrorFactory::Die(Errors::WriteNeighborDataError);
}
My setup of connection on server side:
static void OnNewNeighbor(struct evconnlistener *listener, evutil_socket_t fd,
struct sockaddr *sa, int socklen, void *user_data)
{
struct bufferevent *bev;
Neighbor* new_neighbor;
bev = bufferevent_socket_new(EventLoop::base, fd, BEV_OPT_CLOSE_ON_FREE);
if (!bev)
ErrorFactory::Die(Errors::OnNewNeighborBufEventError);
new_neighbor = AddNeighbor(bev,-1);
bufferevent_setcb(bev,OnNeighborRead,NULL,OnNeighborEvent,new_neighbor);
bufferevent_enable(bev,EV_READ);
Hello(new_neighbor);
fprintf(stderr,"some1 connectefd\n");
}
My setup of connection on client side:
static void Connect(Peer *tmp)
{
sock = socket(PF_INET,SOCK_STREAM,0);
if (sock < 0)
ErrorFactory::Die(Errors::OnFoundNeighborsSockInitError);
bev = bufferevent_socket_new(EventLoop::base,sock,BEV_OPT_CLOSE_ON_FREE);
if (bev==NULL)
ErrorFactory::Die(Errors::OnFoundNeighborsBufferEventNewError);
//fprintf(stderr,"hostname: %s, port: %d, peer_id: %d\n",tmp->hostname,tmp->port,tmp->peer_id);
if(bufferevent_socket_connect_hostname(bev,NULL,AF_INET,tmp->hostname,tmp->port)==-1)
{
ErrorFactory::LogError(log_level,Errors::OnFoundNeighborsConnectError);
continue;
}
neighbor = NeighborObject::AddNeighbor(bev,tmp->peer_id);
bufferevent_setcb(bev,NeighborObject::OnNeighborRead,NULL,NeighborObject::OnNeighborEvent,neighbor);
bufferevent_enable(bev,EV_READ);
NeighborObject::Hello(neighbor);
}
OnNeighborRead is the same function in both variants and is equal to OnRead function in previous post.
Libevent setup:
int Init()
{
base = event_base_new();
if (!base)
return ErrorFactory::LogError(log_level,Errors::InitNewBaseError);
Private::signal_event = evsignal_new(base, SIGINT,OnError, NULL);
if (!Private::signal_event || event_add(Private::signal_event, NULL)<0)
return ErrorFactory::LogError(log_level,Errors::InitSignalAddError);
return 0;
}
void Start()
{
event_base_dispatch(base);
}
Still got this problem. If i try to send data with nc (netcat) everything is going fine. So probably my send function is not valid?***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.