Author: bdonlan
Date: 2004-12-30 00:36:41 -0500 (Thu, 30 Dec 2004)
New Revision: 473
Added:
trunk/clients/ncurses/lineio.c
trunk/clients/ncurses/lineio.h
trunk/clients/ncurses/net.c
Modified:
trunk/
trunk/clients/ncurses/Makefile.am
trunk/clients/ncurses/main.c
trunk/clients/ncurses/net.h
Log:
[EMAIL PROTECTED]: bdonlan | 2004-12-30T05:36:20.976689Z
Committing some early work toward havercurs network I/O.
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:4617
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
+ 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:10209
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
Modified: trunk/clients/ncurses/Makefile.am
===================================================================
--- trunk/clients/ncurses/Makefile.am 2004-12-30 05:07:45 UTC (rev 472)
+++ trunk/clients/ncurses/Makefile.am 2004-12-30 05:36:41 UTC (rev 473)
@@ -6,4 +6,6 @@
display.c display.h \
event.c event.h \
entry.c entry.h \
- mymalloc.c mymalloc.h
+ mymalloc.c mymalloc.h \
+ net.c net.h \
+ lineio.c lineio.h
Added: trunk/clients/ncurses/lineio.c
===================================================================
--- trunk/clients/ncurses/lineio.c 2004-12-30 05:07:45 UTC (rev 472)
+++ trunk/clients/ncurses/lineio.c 2004-12-30 05:36:41 UTC (rev 473)
@@ -0,0 +1,19 @@
+struct lineio_conn {
+ char *outbuf = NULL;
+ size_t outbuf_used, outbuf_len;
+ char *inbuf = NULL;
+ size_t inbuf_used, inbuf_len;
+
+ lineio_callback *cb;
+ void *baton;
+
+ int fd;
+};
+
+#include "lineio.h"
+#include "mymalloc.h"
+#include "event.h"
+#include <stdlib.h>
+#include <unistd.h>
+
+
Property changes on: trunk/clients/ncurses/lineio.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/clients/ncurses/lineio.h
===================================================================
--- trunk/clients/ncurses/lineio.h 2004-12-30 05:07:45 UTC (rev 472)
+++ trunk/clients/ncurses/lineio.h 2004-12-30 05:36:41 UTC (rev 473)
@@ -0,0 +1,23 @@
+/* vim: set ts=4 sw=4 expandtab si ai sta tw=104: */
+#ifndef LINEIO_H
+#define LINEIO_H 1
+
+enum lineio_events {
+ LINEIO_GOTLINE,
+ LINEIO_FLUSHED,
+ LINEIO_DISCON,
+ LINEIO_ERROR
+};
+
+struct lineio_conn;
+typedef struct lineio_conn lineio_conn;
+typedef void lineio_callback(
+ struct lineio_conn *conn, int fd, void *baton,
+ enum lineio_events ev, void *data
+ );
+
+lineio_conn *lineio_attach(int fd, lineio_callback *cb, void *baton);
+void lineio_detatch(lineio_conn *conn);
+int lineio_printf(lineio_callback *cb, char *fmt, ...);
+
+#endif
Property changes on: trunk/clients/ncurses/lineio.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/clients/ncurses/main.c
===================================================================
--- trunk/clients/ncurses/main.c 2004-12-30 05:07:45 UTC (rev 472)
+++ trunk/clients/ncurses/main.c 2004-12-30 05:36:41 UTC (rev 473)
@@ -18,6 +18,7 @@
int main(void) {
int i;
signal(SIGINT, finish); /* arrange interrupts to terminate */
+ signal(SIGIO, SIG_IGN); /* we select() for async I/O */
initscr();
nonl();
cbreak();
Added: trunk/clients/ncurses/net.c
===================================================================
--- trunk/clients/ncurses/net.c 2004-12-30 05:07:45 UTC (rev 472)
+++ trunk/clients/ncurses/net.c 2004-12-30 05:36:41 UTC (rev 473)
@@ -0,0 +1,46 @@
+#include "net.h"
+#include <sys/socket.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <netdb.h>
+extern int h_errno;
+
+/* FIXME: not actually async */
+void net_async_connect(
+ net_conn_callback *cb, void *baton,
+ const char *host, unsigned long port
+ )
+{
+ struct hostent *h;
+ int fd;
+ int pf;
+ int ret;
+ h = gethostbyname(host);
+ if (!h) {
+ cb(baton, -1, h_errno, hstrerror(h_errno));
+ return;
+ }
+ if (h->h_addrtype == AF_INET) {
+ pf = PF_INET;
+ } else {
+ pf = PF_INET6;
+ }
+ fd = socket(pf, SOCK_STREAM, 0);
+ if (fd < 0) {
+ cb(baton, -1, errno, strerror(errno));
+ return;
+ }
+ ret = connect(fd, (const struct sockaddr *)h->h_addr_list[0],
h->h_length);
+ if (ret != 0) {
+ int err = errno;
+ close(fd);
+ cb(baton, -1, err, strerror(err));
+ return;
+ }
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ cb(baton, fd, 0, NULL);
+}
Property changes on: trunk/clients/ncurses/net.c
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/clients/ncurses/net.h
===================================================================
--- trunk/clients/ncurses/net.h 2004-12-30 05:07:45 UTC (rev 472)
+++ trunk/clients/ncurses/net.h 2004-12-30 05:36:41 UTC (rev 473)
@@ -2,6 +2,17 @@
#ifndef NET_H
#define NET_H 1
+/* This is mostly a placeholder right now. Sometime in the future
+ * this should become truly asynchronous.
+ */
+typedef void net_conn_callback(
+ void *baton, int fd, int ecode, const char *error
+ );
+void net_async_connect(
+ net_conn_callback *cb, void *baton,
+ const char *host, unsigned long port
+ );
+
#endif