Enable NODELAY for TCP connections
[bcusdk.git] / eibd / libserver / server.cpp
blob48e6f8f5852ccd3d649ce6f191dae8b6cca86910
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2007 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <unistd.h>
21 #include "server.h"
22 #include "client.h"
25 Server::~Server ()
27 TRACEPRINTF (t, 8, this, "StopServer");
28 Stop ();
29 for (int i = 0; i < connections (); i++)
30 connections[i]->StopDelete ();
31 while (connections () != 0)
32 pth_yield (0);
34 close (fd);
35 TRACEPRINTF (t, 8, this, "Server ended");
38 bool
39 Server::deregister (ClientConnection * con)
41 for (unsigned i = 0; i < connections (); i++)
42 if (connections[i] == con)
44 connections.deletepart (i, 1);
45 return 1;
47 return 0;
50 Server::Server (Layer3 * layer3, Trace * tr)
52 t = tr;
53 l3 = layer3;
56 void
57 Server::Run (pth_sem_t * stop1)
59 pth_event_t stop = pth_event (PTH_EVENT_SEM, stop1);
60 while (pth_event_status (stop) != PTH_STATUS_OCCURRED)
62 int cfd;
63 cfd = pth_accept_ev (fd, 0, 0, stop);
64 if (cfd != -1)
66 TRACEPRINTF (t, 8, this, "New Connection");
67 setupConnection (cfd);
68 ClientConnection *c = new ClientConnection (this, l3, t, cfd);
69 connections.setpart (&c, connections (), 1);
70 c->Start ();
73 pth_event_free (stop, PTH_FREE_THIS);
76 void
77 Server::setupConnection (int cfd)