diff -Nru xine-0.7.5/xineLib.c xine-0.7.5+net/xineLib.c --- xine-0.7.5/xineLib.c 2005-08-14 19:46:08.000000000 +0200 +++ xine-0.7.5+net/xineLib.c 2005-08-16 14:02:11.000000000 +0200 @@ -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) @@ -1941,6 +1945,34 @@ 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 = 0; + 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()); @@ -2017,6 +2049,25 @@ } ::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; @@ -2049,6 +2100,11 @@ ::unlink(m_fifoNameRemote.c_str()); ::unlink(m_fifoNameStream.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) @@ -2300,12 +2356,37 @@ // 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::checkConnect() { + + /* files */ // bool reinit = false; // if (-1 == fd_fifo0) // { +// +/* fd_fifo0 = ::open(m_fifoNameStream.c_str(), O_WRONLY | O_NONBLOCK); if (-1 == fd_fifo0) return false; @@ -2321,6 +2402,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.5/xineLib.h xine-0.7.5+net/xineLib.h --- xine-0.7.5/xineLib.h 2005-08-14 12:55:10.000000000 +0200 +++ xine-0.7.5+net/xineLib.h 2005-08-16 12:18:50.000000000 +0200 @@ -137,7 +137,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;