summaryrefslogtreecommitdiff
path: root/tcp.h
diff options
context:
space:
mode:
Diffstat (limited to 'tcp.h')
-rw-r--r--tcp.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/tcp.h b/tcp.h
new file mode 100644
index 0000000..a09732a
--- /dev/null
+++ b/tcp.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "global.h"
+
+//Unless specified otherwise, functions return -1 on error or socket closure.
+
+//If *bufsz==0 || *buf==NULL, allocates buf newly.
+//Returns line length; reallocates buf if needed.
+i64 tcp_read_line(int sock,char **buf,i64 *bufsz);
+
+i64 tcp_read_data(int sock,char *buf,i64 length);
+
+i64 tcp_send_data(int sock,const char *buf,i64 length);
+i64 tcp_send_str(int sock,const char *str);
+i64 tcp_send_line(int sock,const char *str);
+i64 tcp_send_line_f(int sock,const char *format,...) __attribute__((format (printf,2,3)));
+
+
+i64 tcp_read_ok(int sock,const char *tag);
+
+typedef struct TcpList{
+ i64 nitems;
+ char **items;
+} TcpList;
+
+//Returns NULL on error instead of -1.
+TcpList* tcp_read_list(int sock,const char *tag);
+
+
+//Returns the socket.
+int tcp_connect(const char *hostname,int port);