diff -Nru xine-0.7.7.orig/xine.c xine-0.7.7/xine.c --- xine-0.7.7.orig/xine.c 2006-01-15 00:47:12.000000000 +0100 +++ xine-0.7.7/xine.c 2006-02-20 17:36:48.000000000 +0100 @@ -33,7 +33,7 @@ public: PluginXine::cXineLib *m_xineLib; - int m_instanceNo; + in_addr_t m_bindIp; cPluginXine(void); virtual ~cPluginXine(); @@ -56,7 +56,7 @@ , m_remote(0) , m_remoteOn(false) , m_xineLib(0) - , m_instanceNo(-1) + , m_bindIp(0) { // Initialize any member variables here. // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL @@ -73,7 +73,7 @@ //Return a string that describes all known command line options. //" - -- x \n" return - " -i N instance number to append to FIFO directory\n" + " -i ip ip address to bind to\n" " -q turn off debug messages on console\n" " -r turn on remote (pressing keys in xine controls VDR)\n" " -s switch to curses skin, while xine is disconnected\n" @@ -93,11 +93,9 @@ { case 'i': { - const int no = ::atoi(::optarg); - if (no < 0) + m_bindIp = inet_addr(::optarg); + if (m_bindIp == INADDR_NONE) return false; - - m_instanceNo = no; } break; @@ -203,9 +201,9 @@ namespace PluginXine { - int GetInstanceNo(cPlugin *const plugin) + int GetBindIp(cPlugin *const plugin) { - return ((cPluginXine *)plugin)->m_instanceNo; + return ((cPluginXine *)plugin)->m_bindIp; } cXineLib *&GetXineLib(cPlugin *const plugin) diff -Nru xine-0.7.7.orig/xineLib.c xine-0.7.7/xineLib.c --- xine-0.7.7.orig/xineLib.c 2006-02-12 22:36:48.000000000 +0100 +++ xine-0.7.7/xineLib.c 2006-02-20 18:06:02.000000000 +0100 @@ -1847,7 +1847,7 @@ #endif - extern int GetInstanceNo(cPlugin *const plugin); + extern int GetBindIp(cPlugin *const plugin); extern cXineLib *&GetXineLib(cPlugin *const plugin); cXineLib::cXineLib(cPlugin *const plugin, const cXineSettings &settings, cMutex &osdMutex, cXineRemote *const remote) @@ -1855,6 +1855,10 @@ , m_plugin(plugin) , m_settings(settings) , m_osdFlushRequired(false) + , fd_fifo0_serv(-1) + , fd_result_serv(-1) + , fd_control_serv(-1) + , fd_remote_serv(-1) , fd_fifo0(-1) , fd_result(-1) , fd_control(-1) @@ -1873,14 +1877,9 @@ { m_fifoDir = FIFO_DIR; - if (GetInstanceNo(plugin) >= 0) - { - char s[ 20 ]; - ::sprintf(s, "%d", GetInstanceNo(plugin)); - - m_fifoDir += s; - } - + m_bindIp = GetBindIp(plugin); + m_fifoDir += itoa(m_bindIp); + m_fifoNameControl = m_fifoDir + "/stream.control"; m_fifoNameResult = m_fifoDir + "/stream.result"; m_fifoNameRemote = m_fifoDir + "/stream.event"; @@ -1962,9 +1961,37 @@ m_eventSink = eventSink; } + int cXineLib::CreateServerSocket(unsigned short port) + { + int fd; + int onoff = 1; + struct sockaddr_in sain; + + if ((fd = ::socket(PF_INET,SOCK_STREAM,0)) < 0) { + perror("socket failed."); + return -1; + } + + sain.sin_addr.s_addr = m_bindIp; + sain.sin_port = htons(port); + + ::setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&onoff, sizeof(int) ); + + if (::bind(fd,(struct sockaddr*)&sain, sizeof(sain)) != 0) { + perror("bind failed."); + return -1; + } + + if (::listen(fd,1) != 0) { + printf("listen failed."); + return -1; + } + return fd; + } + bool cXineLib::Open() { - ::unlink(m_fifoNameExtControl.c_str()); +/* ::unlink(m_fifoNameExtControl.c_str()); ::unlink(m_fifoNameExtResult.c_str()); ::unlink(m_fifoNameControl.c_str()); ::unlink(m_fifoNameResult.c_str()); @@ -2003,6 +2030,26 @@ #undef MkFifo ::umask(origUmask); +*/ +/* +{ .path = FIFO_STREAM, .mode = 0644, .port = 18701 }, +{ .path = FIFO_STREAM_CONTROL, .mode = 0644, .port = 18702 }, +{ .path = FIFO_STREAM_RESULT, .mode = 0666, .port = 18703 }, +{ .path = FIFO_STREAM_EVENT, .mode = 0666, .port = 18704 }, + +*/ + /* sockets - create the server sockets */ + if ((fd_fifo0_serv = CreateServerSocket(18701)) == -1) + return false; + + if ((fd_control_serv = CreateServerSocket(18702)) == -1) + return false; + + if ((fd_result_serv = CreateServerSocket(18703)) == -1) + return false; + + if ((fd_remote_serv = CreateServerSocket(18704)) == -1) + return false; if (!Start()) return false; @@ -2028,13 +2075,18 @@ disconnect(); } - ::unlink(m_fifoNameExtControl.c_str()); +/* ::unlink(m_fifoNameExtControl.c_str()); ::unlink(m_fifoNameExtResult.c_str()); ::unlink(m_fifoNameControl.c_str()); ::unlink(m_fifoNameResult.c_str()); ::unlink(m_fifoNameRemote.c_str()); ::unlink(m_fifoNameStream.c_str()); - ::rmdir(m_fifoDir.c_str()); + ::rmdir(m_fifoDir.c_str()); */ + + ::close(fd_remote_serv); + ::close(fd_result_serv); + ::close(fd_control_serv); + ::close(fd_fifo0_serv); } void cXineLib::internalPaused(const bool paused) @@ -2286,6 +2338,28 @@ // fprintf(stderr, "Action done\n"); } +int cXineLib::SocketAcceptHelper(int fd) +{ + // use cPoller for checking server socket for incoming requests + cPoller poller(fd,0); /* POLLIN */ + struct sockaddr sain; + socklen_t len = sizeof(sain); + int client; + +// ::fprintf(stderr,"vdr-xine: polling for connection on %d...\n",fd); + if (!poller.Poll(100)) + return -1; + +// ::fprintf(stderr,"vdr-xine: incoming requests on %d\n",fd); + if ((client = ::accept(fd,(struct sockaddr *) &sain,&len)) == -1) { + ::fprintf(stderr,"vdr-xine: fifo0 failed to accept...\n"); + return -1; + } +// ::fprintf(stderr,"vdr-xine: successful request on %d (client: %d)\n",fd,client); + return client; +} + + bool cXineLib::checkXineVersion() { int32_t version = 0; @@ -2306,7 +2380,8 @@ // if (-1 == fd_fifo0) // { - fd_fifo0 = ::open(m_fifoNameStream.c_str(), O_WRONLY | O_NONBLOCK); +/* + fd_fifo0 = ::open(m_fifoNameStream.c_str(), O_WRONLY | O_NONBLOCK); if (-1 == fd_fifo0) return false; @@ -2321,6 +2396,23 @@ ::fcntl(fd_fifo0 , F_SETFL, ~O_NONBLOCK & ::fcntl(fd_fifo0 , F_GETFL, 0)); ::fcntl(fd_remote, F_SETFL, ~O_NONBLOCK & ::fcntl(fd_remote, F_GETFL, 0)); +*/ + /* sockets */ + + if (fd_fifo0_serv == -1) + return false; + + if ((fd_fifo0 = SocketAcceptHelper(fd_fifo0_serv)) == -1) + return false; + + if ((fd_control = SocketAcceptHelper(fd_control_serv)) == -1) + return false; + + if ((fd_result = SocketAcceptHelper(fd_result_serv)) == -1) + return false; + + if ((fd_remote = SocketAcceptHelper(fd_remote_serv)) == -1) + return false; internalPaused(false); diff -Nru xine-0.7.7.orig/xineLib.h xine-0.7.7/xineLib.h --- xine-0.7.7.orig/xineLib.h 2006-02-03 22:16:46.000000000 +0100 +++ xine-0.7.7/xineLib.h 2006-02-20 17:36:48.000000000 +0100 @@ -88,6 +88,7 @@ string m_fifoNameStream; string m_fifoNameExtControl; string m_fifoNameExtResult; + in_addr_t m_bindIp; private: cPlugin *const m_plugin; @@ -137,7 +138,13 @@ } private: + /* sockets */ + int CreateServerSocket(unsigned short port); + int SocketAcceptHelper(int fd); + int fd_fifo0_serv, fd_result_serv, fd_control_serv, fd_remote_serv; int fd_fifo0, fd_result, fd_control, fd_remote; + + cMutex m_ioMutex, m_dataMutex, m_disconnectMutex; cMutex &m_osdMutex;