summaryrefslogtreecommitdiff
path: root/tools/cxsocket.h
diff options
context:
space:
mode:
authorphintuka <phintuka>2006-12-31 20:19:32 +0000
committerphintuka <phintuka>2006-12-31 20:19:32 +0000
commit5b2a257024092e3a92ff934235cd9c8b24e4d970 (patch)
treeb5b9fc6a3d92df15814ac2cdf078cd56d68f4c41 /tools/cxsocket.h
parente11e77c3b98618d6d5e8fa2b070c0bef4e4c5631 (diff)
downloadxineliboutput-5b2a257024092e3a92ff934235cd9c8b24e4d970.tar.gz
xineliboutput-5b2a257024092e3a92ff934235cd9c8b24e4d970.tar.bz2
moved readline_cmd to cxsocket.c
Diffstat (limited to 'tools/cxsocket.h')
-rw-r--r--tools/cxsocket.h63
1 files changed, 9 insertions, 54 deletions
diff --git a/tools/cxsocket.h b/tools/cxsocket.h
index 1c29a7ca..7339d8e0 100644
--- a/tools/cxsocket.h
+++ b/tools/cxsocket.h
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: cxsocket.h,v 1.15 2006-12-31 20:14:15 phintuka Exp $
+ * $Id: cxsocket.h,v 1.16 2006-12-31 20:19:32 phintuka Exp $
*
*/
@@ -53,6 +53,14 @@ class cxSocket {
{ return write(str, len ?: strlen(str), timeout_ms); }
ssize_t write_cmd(int fd, const char *str, int len=0)
{ return write(str, len ?: strlen(str), 10); }
+
+/* readline return value:
+ * <0 : failed
+ * >=maxsize : buffer overflow
+ * >=0 : if errno = EAGAIN -> line is not complete (there was timeout)
+ * if errno = 0 -> succeed
+ * (return value 0 indicates empty line "\r\n")
+ */
ssize_t readline(char *buf, int bufsize, int timeout=0, int bufpos=0);
bool SetBuffers(int Tx, int Rx);
@@ -318,59 +326,6 @@ static inline ssize_t printf_cmd(int fd, const char *fmt, ...)
return (ssize_t)-1;
}
-/* return value:
- * maxsize : buffer overflow
- * 0 :
- * if errno = EAGAIN : timeout
- * 0...max-1 : succeed. (0 indicates empty line (\r\n))
- * if errno = EAGAIN line is not complete (there was timeout)
- * <0 : failed
- */
-static int readline_cmd(int fd, char *buf, int bufsize, int timeout=0, int bufpos=0)
-{
- int n = -1, cnt = bufpos;
- cPoller p(fd);
-
- do {
- if(timeout>0 && !p.Poll(timeout)) {
- errno = EAGAIN;
- return cnt;
- }
-
- while((n = read(fd, buf+cnt, 1)) == 1) {
- buf[++cnt] = 0;
-
- if( cnt > 1 && buf[cnt - 2] == '\r' && buf[cnt - 1] == '\n') {
- cnt -= 2;
- buf[cnt] = 0;
- errno = 0;
- return cnt;
- }
-
- if( cnt >= bufsize) {
- LOGMSG("readline_cmd: too long control message (%d bytes): %20s", cnt, buf);
- errno = 0;
- return bufsize;
- }
- }
-
- /* connection closed ? */
- if (n == 0) {
- LOGMSG("readline_cmd: disconnected");
- if(errno == EAGAIN)
- errno = ENOTCONN;
- return -1;
- }
-
- } while (timeout>0 && n<0 && errno == EAGAIN);
-
- if(errno == EAGAIN)
- return cnt;
-
- LOGERR("readline_cmd: read failed");
- return n;
-}
-
#include "../config.h"
#include "../xine_input_vdr_net.h"
static inline int udp_discovery_broadcast(int fd_discovery, int m_Port)