From: Darren S. <ds...@us...> - 2006-02-21 19:27:50
|
Update of /cvsroot/xine/gnome-xine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22456/src Modified Files: server.c server.h Log Message: Update FSF address and do some code cleanup. Index: server.c =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/server.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- server.c 16 Feb 2006 18:44:13 -0000 1.20 +++ server.c 21 Feb 2006 19:27:47 -0000 1.21 @@ -1,6 +1,6 @@ /* * Copyright (C) 2002 Stefan Holst - * Copyright (C) 2003-2005 the xine project team + * Copyright (C) 2003-2006 the xine project team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * $Id$ * @@ -49,16 +49,14 @@ static pthread_t server_thread; /* create an unix domain socket */ -static int make_socket (char *path) { - - int sock; +static int make_socket (char *path) +{ struct sockaddr_un adr = {0}; - - sock = socket (PF_UNIX, SOCK_STREAM, 0); - if (sock < 0) { + int sock = socket (PF_UNIX, SOCK_STREAM, 0); + if (sock < 0) + { perror ("socket"); return -1; -// exit (EXIT_FAILURE); } unlink (path); @@ -69,10 +67,10 @@ strncpy (adr.sun_path, path, sizeof (adr.sun_path)-1); /* bind the name to the descriptor */ - if (bind (sock, (struct sockaddr *) &adr, sizeof (adr)) < 0) { + if (bind (sock, (struct sockaddr *) &adr, sizeof (adr)) < 0) + { perror ("bind"); return -1; -// exit (EXIT_FAILURE); } logprintf ("server: socket '%s' created \n", path); @@ -80,52 +78,16 @@ return sock; } -#if 0 -/* - * Check for socket validity. - */ -static int sock_check_opened(int socket) { - fd_set readfds, writefds, exceptfds; - int retval; - struct timeval timeout; - - for(;;) { - FD_ZERO(&readfds); - FD_ZERO(&writefds); - FD_ZERO(&exceptfds); - FD_SET(socket, &exceptfds); - - timeout.tv_sec = 0; - timeout.tv_usec = 0; - - retval = select(socket + 1, &readfds, &writefds, &exceptfds, &timeout); - - if(retval == -1 && (errno != EAGAIN && errno != EINTR)) - return 0; - - if (retval != -1) - return 1; - } - - return 0; -} -#endif - -static void sock_write (int fd, char *msg) { - - int len, pos; - - len = strlen (msg); - pos = 0; - - while (pos<len) { - - int n=0; +static void sock_write (int fd, char *msg) +{ + int len = strlen (msg); + int pos = 0; - n = write (fd, msg+pos, len-pos); + while (pos < len) + { + int n = write (fd, msg+pos, len-pos); - if (n<=0) { - + if (n <= 0) switch (errno) { case EAGAIN: continue; @@ -133,14 +95,14 @@ perror ("server: write error"); return; } - } - - pos += n; + else + pos += n; } } -static void error_report (void *s, const char *msg, ...) { - +static void __attribute__ ((format (printf, 2, 3))) +error_report (void *s, const char *msg, ...) +{ int fd = *(int *)s; char *amsg; va_list ap; @@ -155,24 +117,29 @@ static int running; -static void *socket_listener (void *data) { - - struct sockaddr_un client; - socklen_t size; - int s; - char buf[BUF_SIZE+1]; - int buf_len; - int listening; +static void *socket_listener (void *data) +{ + listen (gxsocket, 1); + while (running) + { + struct sockaddr_un client; + socklen_t size; + char buf[BUF_SIZE + 1]; + int s = accept (gxsocket, (struct sockaddr *) &client, &size); - listen (gxsocket,1); + if (s == -1) + { + perror ("accept"); + sleep (1); + continue; + } - while (running) { - s = accept (gxsocket, (struct sockaddr *) &client, &size); logprintf ("server: connected.\n"); sock_write(s, _("This is gxine\n\nJavascript interface. Type 'help();' for help.\n")); - buf_len = 0; - listening = 1; + int buf_len = 0; + int listening = 1; + while (listening) { int n = read (s, buf + buf_len, 1); @@ -260,16 +227,16 @@ signal (SIGPIPE, sigpipe_handler); } -int server_client_connect (void) { - +int server_client_connect (void) +{ struct sockaddr_un cli_adr = {0}, serv_adr = {0}; int length = sizeof(struct sockaddr_un); - char filename [1024]; + char filename[PATH_MAX]; signal (SIGPIPE, sigpipe_handler); /* server filename */ - snprintf (filename, 1024, SOCKET_FILENAME, getenv ("HOME")); + snprintf (filename, PATH_MAX, SOCKET_FILENAME, getenv ("HOME")); logprintf ("server: trying to connect to already running instance of gxine (%s)...\n", filename); @@ -284,7 +251,8 @@ unlink (tstr); /* bind the socket to the client's address */ - if (bind (client_fd, (struct sockaddr*) &cli_adr, length) < 0) { + if (bind (client_fd, (struct sockaddr*) &cli_adr, length) < 0) + { perror ("bind"); return 0; } @@ -293,7 +261,8 @@ serv_adr.sun_family = AF_UNIX; strcpy (serv_adr.sun_path, filename); - if (connect (client_fd, (struct sockaddr *) &serv_adr, sizeof (serv_adr)) < 0) { + if (connect (client_fd, (struct sockaddr *) &serv_adr, sizeof (serv_adr)) < 0) + { #ifdef LOG perror ("connect"); #endif @@ -307,13 +276,13 @@ return 1; } -void server_client_send (char *cmd) { - - write (client_fd, cmd, strlen (cmd)); +int server_client_send (const char *cmd) +{ + return write (client_fd, cmd, strlen (cmd)); } -void server_client_stop (void) { - +void server_client_stop (void) +{ if (client_fd < 0) return; Index: server.h =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/server.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- server.h 20 Mar 2003 21:59:58 -0000 1.2 +++ server.h 21 Feb 2006 19:27:47 -0000 1.3 @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * $Id$ * @@ -26,7 +26,7 @@ /* functions to attempt to connect to already running gxine */ int server_client_connect (void); -void server_client_send (char *cmd); +int server_client_send (const char *cmd); void server_client_stop (void); /* if no gxine is running, create our own gxine socket: */ |