From: Frantisek D. <va...@us...> - 2004-04-06 18:53:23
|
Update of /cvsroot/xine/xine-lib/src/xine-engine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13047/src/xine-engine Modified Files: io_helper.c io_helper.h Log Message: Patch for using timeout in cddb lookup (xine was freezed just because of firewall!!!). New functions into io_helper: _x_io_tcp_connect_finish ... wait for successful connect with timeout _x_io_tcp_read_line ... read the string from the socket (improvements neded) Use io_helper functions in input_cdda. Don't try connect again to freedb server, if previous connecting was failed. Index: io_helper.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/xine-engine/io_helper.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- io_helper.c 14 Mar 2004 09:38:03 -0000 1.10 +++ io_helper.c 6 Apr 2004 18:40:32 -0000 1.11 @@ -233,6 +233,33 @@ } +/* + * wait for finish connection + */ +int _x_io_tcp_connect_finish(xine_stream_t *stream, int fd, int timeout_msec) { + int ret; + + ret = _x_io_select(stream, fd, XIO_WRITE_READY, timeout_msec); + + /* find out, if connection is successfull */ + if (ret == XIO_READY) { + socklen_t len = sizeof(int); + int err; + + if ((getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len)) == -1) { + _x_message(stream, XINE_MSG_CONNECTION_REFUSED, _("failed to get status of socket"), strerror(errno), NULL); + return XIO_ERROR; + } + if (err) { + _x_message(stream, XINE_MSG_CONNECTION_REFUSED, strerror(errno), NULL); + return XIO_ERROR; + } + } + + return ret; +} + + static off_t xio_rw_abort(xine_stream_t *stream, int fd, int cmd, char *buf, off_t todo) { off_t ret = -1; @@ -311,3 +338,29 @@ off_t _x_io_file_write (xine_stream_t *stream, int s, char *buf, off_t todo) { return xio_rw_abort (stream, s, XIO_FILE_WRITE, buf, todo); } + +/* + * read a string from socket, return size length + */ +int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size) { + int i = 0; + char c; + off_t r; + + while ((r = xio_rw_abort(stream, sock, XIO_TCP_READ, &c, 1)) != -1) { + if (c == '\r' || c == '\n') + break; + if (i > size) + break; + + str[i] = c; + i++; + } + + if (r != -1) + r = xio_rw_abort(stream, sock, XIO_TCP_READ, &c, 1); + + str[i] = '\0'; + + return (int)r; +} Index: io_helper.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/xine-engine/io_helper.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- io_helper.h 5 Dec 2003 19:36:11 -0000 1.3 +++ io_helper.h 6 Apr 2004 18:40:32 -0000 1.4 @@ -66,6 +66,11 @@ int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port); /* + * wait for finish connection + */ +int _x_io_tcp_connect_finish(xine_stream_t *stream, int fd, int timeout_msec); + +/* * read from tcp socket checking demux_action_pending * * network input plugins should use this function in order to @@ -107,4 +112,9 @@ */ off_t _x_io_file_write (xine_stream_t *stream, int fd, char *buf, off_t todo); +/* + * read a string from socket, return size length + */ +int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size); + #endif |