2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "mvpserver.h"
23 // undeclared function
24 void MVPServerStartThread(void *arg)
26 MVPServer *m = (MVPServer *)arg;
31 MVPServer::MVPServer()
37 MVPServer::~MVPServer()
44 if (!running) return 0;
49 pthread_cancel(runThread);
50 pthread_join(runThread, NULL);
52 close(listeningSocket);
59 if (running) return 1;
61 log.init(Log::DEBUG, "/tmp/vompserver.log", 0);
63 if (udpr.run() == 0) return 0;
65 if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPServerStartThread, (void *)this) == -1) return 0;
66 log.log("MVPServer", Log::DEBUG, "MVPServer run success");
70 void MVPServer::run2()
73 // I don't want signals and I want to die as soon as I am cancelled because I'll be in accept()
76 pthread_sigmask(SIG_BLOCK, &sigset, NULL);
77 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
78 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
80 struct sockaddr_in address;
81 address.sin_family = AF_INET;
82 address.sin_port = htons(3024);
83 address.sin_addr.s_addr = INADDR_ANY;
84 socklen_t length = sizeof(address);
86 listeningSocket = socket(AF_INET, SOCK_STREAM, 0);
87 if (listeningSocket < 0)
89 log.log("MVPServer", Log::DEBUG, "Could not get TCP socket in vompserver");
94 setsockopt(listeningSocket,SOL_SOCKET,SO_REUSEADDR,&value,sizeof(value));
96 if (bind(listeningSocket,(struct sockaddr *)&address,sizeof(address)) < 0)
98 log.log("MVPServer", Log::DEBUG, "Could not bind to socket in vompserver");
99 close(listeningSocket);
103 listen(listeningSocket, 5);
109 clientSocket = accept(listeningSocket,(struct sockaddr *)&address, &length);
110 MVPClient* m = new MVPClient(clientSocket);
116 ULLONG ntohll(ULLONG a)
121 ULLONG htonll(ULLONG a)
123 #if BYTE_ORDER == BIG_ENDIAN
128 b = ((a << 56) & 0xFF00000000000000ULL)
129 | ((a << 40) & 0x00FF000000000000ULL)
130 | ((a << 24) & 0x0000FF0000000000ULL)
131 | ((a << 8) & 0x000000FF00000000ULL)
132 | ((a >> 8) & 0x00000000FF000000ULL)
133 | ((a >> 24) & 0x0000000000FF0000ULL)
134 | ((a >> 40) & 0x000000000000FF00ULL)
135 | ((a >> 56) & 0x00000000000000FFULL) ;