* _Update() was called too early in the constructor of class Service; that caused
incorrect values in fSet, and fMinSocket which also resulted in select() never to return (in would only work for settings you changed after the net_server was run). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21551 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f5a92f59e4
commit
470ca87e4d
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@ -126,8 +126,6 @@ Services::Services(const BMessage& services)
|
|||||||
fUpdate(0),
|
fUpdate(0),
|
||||||
fMaxSocket(0)
|
fMaxSocket(0)
|
||||||
{
|
{
|
||||||
_Update(services);
|
|
||||||
|
|
||||||
// setup pipe to communicate with the listener thread - as the listener
|
// setup pipe to communicate with the listener thread - as the listener
|
||||||
// blocks on select(), we need a mechanism to interrupt it
|
// blocks on select(), we need a mechanism to interrupt it
|
||||||
if (pipe(&fReadPipe) < 0) {
|
if (pipe(&fReadPipe) < 0) {
|
||||||
@ -144,6 +142,8 @@ Services::Services(const BMessage& services)
|
|||||||
fMinSocket = fWritePipe + 1;
|
fMinSocket = fWritePipe + 1;
|
||||||
fMaxSocket = fWritePipe + 1;
|
fMaxSocket = fWritePipe + 1;
|
||||||
|
|
||||||
|
_Update(services);
|
||||||
|
|
||||||
fListener = spawn_thread(_Listener, "services listener", B_NORMAL_PRIORITY, this);
|
fListener = spawn_thread(_Listener, "services listener", B_NORMAL_PRIORITY, this);
|
||||||
if (fListener >= B_OK)
|
if (fListener >= B_OK)
|
||||||
resume_thread(fListener);
|
resume_thread(fListener);
|
||||||
@ -256,7 +256,8 @@ Services::_StopService(struct service& service)
|
|||||||
for (; iterator != service.addresses.end(); iterator++) {
|
for (; iterator != service.addresses.end(); iterator++) {
|
||||||
const service_address& address = *iterator;
|
const service_address& address = *iterator;
|
||||||
|
|
||||||
ServiceSocketMap::iterator socketIterator = fSocketMap.find(address.socket);
|
ServiceSocketMap::iterator socketIterator
|
||||||
|
= fSocketMap.find(address.socket);
|
||||||
if (socketIterator != fSocketMap.end())
|
if (socketIterator != fSocketMap.end())
|
||||||
fSocketMap.erase(socketIterator);
|
fSocketMap.erase(socketIterator);
|
||||||
|
|
||||||
@ -440,7 +441,8 @@ Services::_LaunchService(struct service& service, int socket)
|
|||||||
pid_t child = fork();
|
pid_t child = fork();
|
||||||
if (child == 0) {
|
if (child == 0) {
|
||||||
setsid();
|
setsid();
|
||||||
// make sure we're in our own session, and don't accidently quit the net_server
|
// make sure we're in our own session, and don't accidently quit
|
||||||
|
// the net_server
|
||||||
|
|
||||||
// We're the child, replace standard input/output
|
// We're the child, replace standard input/output
|
||||||
dup2(socket, STDIN_FILENO);
|
dup2(socket, STDIN_FILENO);
|
||||||
@ -480,7 +482,6 @@ Services::_Listener()
|
|||||||
snooze(1000000LL);
|
snooze(1000000LL);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("select returned!\n");
|
|
||||||
if (FD_ISSET(fReadPipe, &set)) {
|
if (FD_ISSET(fReadPipe, &set)) {
|
||||||
char command;
|
char command;
|
||||||
if (read(fReadPipe, &command, 1) == 1 && command == 'q')
|
if (read(fReadPipe, &command, 1) == 1 && command == 'q')
|
||||||
|
Loading…
Reference in New Issue
Block a user