You are not logged in.

#1 2008-12-06 22:46:48

Envil
Member
Registered: 2008-11-18
Posts: 52

[Solved] poll returns POLLHUP for socket after successfull connect()

I have a program which runs multiple threads, each thread opens a listening socket and waits for connections.
For each connection that i accept i do a connect() on a new socket to another host (the program acts as relay between the client and the other host).

This works fine in the first thread, however in the 2nd thread i get a POLLHUP from poll() for my newly connected socket right after connecting it.
In this case it doesnt matter if the first thread has a open connection or not, even ending the first thread doesnt change it.

Is this a problem because of threading in general or did i mess up somewhere? Couldnt find anything usefull on google about this.

Sources: http://www.ivory-tower.de/tcp_relay.tar.gz

Im still learning so excuse me if the code is newbie'sh =P

Last edited by Envil (2008-12-10 20:39:18)

Offline

#2 2008-12-10 15:34:34

wu.soldier
Member
From: Poland
Registered: 2006-12-19
Posts: 22

Re: [Solved] poll returns POLLHUP for socket after successfull connect()

Hi !
You shouldn't be initializing and then calling connect() on a handle which was returned by accept() because accept() returns handle to opened and initilized socket (if it's != -1) . You're overwriting that valid handle and you're trying to connect to the client. Check this: http://beej.us/guide/bgnet/output/html/ … index.html - it may help you.

Offline

#3 2008-12-10 20:38:49

Envil
Member
Registered: 2008-11-18
Posts: 52

Re: [Solved] poll returns POLLHUP for socket after successfull connect()

I did not call connect() on the accept socket, as i wrote i initialized a new one for that.
However i already solved this, problem just was that the thread_id was not set correctly and due to that all further threads did not have AF_INET set on their remote sockets.

Offline

Board footer

Powered by FluxBB