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 MVPServer::MVPServer()
27 MVPServer::~MVPServer()
34 if (threadIsActive()) threadCancel();
35 close(listeningSocket);
39 log.log("Main", Log::INFO, "Stopped main server thread");
49 if (threadIsActive()) return 1;
52 const char* configDir = cPlugin::ConfigDirectory();
55 dsyslog("VOMP: Could not get config dir from VDR");
59 char configFileName[PATH_MAX];
60 snprintf(configFileName, PATH_MAX, "%s/vomp.conf", configDir);
61 if (config.init(configFileName))
63 dsyslog("VOMP: Config file found");
67 dsyslog("VOMP: Config file not found");
73 char* cfgLogFilename = config.getValueString("General", "Log file");
76 log.init(Log::DEBUG, cfgLogFilename);
77 delete[] cfgLogFilename;
80 // Work out a name for this server
84 // Try to get from vomp.conf
85 serverName = config.getValueString("General", "Server name");
86 if (!serverName) // If not, get the hostname
88 serverName = new char[1024];
89 if (gethostname(serverName, 1024)) // if not, just use "-"
91 strcpy(serverName, "-");
95 int udpSuccess = udpr.run(serverName);
101 log.log("Main", Log::CRIT, "Could not start UDP replier");
109 log.log("Main", Log::CRIT, "Could not start MVPServer thread");
114 log.log("Main", Log::DEBUG, "MVPServer run success");
118 void MVPServer::threadMethod()
120 // I want to die as soon as I am cancelled because I'll be in accept()
121 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
122 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
124 struct sockaddr_in address;
125 address.sin_family = AF_INET;
126 address.sin_port = htons(3024);
127 address.sin_addr.s_addr = INADDR_ANY;
128 socklen_t length = sizeof(address);
130 listeningSocket = socket(AF_INET, SOCK_STREAM, 0);
131 if (listeningSocket < 0)
133 log.log("MVPServer", Log::CRIT, "Could not get TCP socket in vompserver");
138 setsockopt(listeningSocket,SOL_SOCKET,SO_REUSEADDR,&value,sizeof(value));
140 if (bind(listeningSocket,(struct sockaddr *)&address,sizeof(address)) < 0)
142 log.log("MVPServer", Log::CRIT, "Could not bind to socket in vompserver");
143 close(listeningSocket);
147 listen(listeningSocket, 5);
153 clientSocket = accept(listeningSocket,(struct sockaddr *)&address, &length);
154 MVPClient* m = new MVPClient(clientSocket);