Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Nov 1999 15:36:49 -0500
From:      Dan Moschuk <dan@FreeBSD.ORG>
To:        Rob King <dimwit@pernet.net>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: PThreads and Sockets
Message-ID:  <19991126153649.A1358@spirit.jaded.net>
In-Reply-To: <Pine.BSF.4.20.9911261320150.11874-100000@deadpixi.pernet.net>; from dimwit@pernet.net on Fri, Nov 26, 1999 at 01:20:52PM -0600
References:  <Pine.BSF.4.20.9911261320150.11874-100000@deadpixi.pernet.net>

next in thread | previous in thread | raw e-mail | index | archive | help

| Hi all,
|   I'm writing a server that multiplexes a MySQL connection to several
| clients. Since the connection has to be shared, I can't fork(), I have to
| thread. This isn't a problem, except that when I accept() and assign a
| socket descriptor, the first thread runs fine, but the next thread simply
| grabs the descriptor (since it's shared) from the previous thread and
| starts doing all its writing to that socket. Any idea how to get around
| this? If there's any good example code, please let me know.
| 
| Thanks,
| Rob

Err, how exactly is your server model setup?  Do you create a thread after
the accept call to handle the connection, or do you pre-spawn threads in a
pool?

If you allocate the socket descriptor for the client in the starting routine
for the thread, it should have its own copy.

-- 
Dan Moschuk (TFreak!dan@freebsd.org)
"Cure for global warming: One giant heatsink and dual fans!"


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991126153649.A1358>