Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

WinSock w/ pthreads, C++

Name: Anonymous 2008-10-13 5:49

I'm testing a concept so excuse the messy code, it's my first time really using pthreads at all. Running into a bit of a problem; it handles the first client that connects just fine, but none afterward. At first I thought it had something to do with my accept socket, because if I closed the accept socket after setting it to the socket in my thread's object, it would close the connection, so I made an array of accept sockets. Still not working.

In short, I don't want bitching about my coding style, etcetera, as I just threw this together to see how it works. It's most certainly not going to be used in anything; it's just a learning tool of sorts. If anyone can find where and why it's not working as I intend it to, I'd greatly appreciate an explanation.

Code: http://pastebin.com/m47bff01e

Thanks.

Name: Anonymous 2008-10-14 5:52

Yeah, OP here.

Love how you all comment on everything BUT the problem... you know, the exact thing I asked you not to do? I'm not looking for criticism on the writing style, etcetera. I know it's bad, I know how to improve it already. It's just some trash thrown together to try out pthreads. I'm trying to figure out why it's only handling the first socket and the first thread at a time. It almost seems as if something is blocking -- which, I've been led to believe, should not be the case with threads created using pthread_create()... and I don't see anything blocking other than listen and the accept loop in the main thread, and those are intended to.

>>2
As you can see, after the accept socket picks up a connection, it gets passed to a socket in the struct array. If I close the accept socket, it closes the connection that was passed as well, effectively closing both the accept socket and the socket in the struct.

The array of accept sockets was just for me to look at their behavior a little further. It doesn't really have a need here.

It's called "learning."

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List