Author: bdonlan
Date: 2004-12-30 01:15:23 -0500 (Thu, 30 Dec 2004)
New Revision: 476
Modified:
trunk/
trunk/clients/ncurses/main.c
Log:
[EMAIL PROTECTED]: bdonlan | 2004-12-30T06:14:11.389136Z
Add some test code for lineio and net to main. Not currently working.
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:10215
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
+ 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:10216
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
Modified: trunk/clients/ncurses/main.c
===================================================================
--- trunk/clients/ncurses/main.c 2004-12-30 06:15:09 UTC (rev 475)
+++ trunk/clients/ncurses/main.c 2004-12-30 06:15:23 UTC (rev 476)
@@ -10,11 +10,23 @@
#include "display.h"
/*#include "io.h"*/
#include "event.h"
+#include "net.h"
+#include "lineio.h"
void finish(int);
void handle_input(int fd, int mode, void *baton);
void heartbeat(const struct timeval *when, void *baton);
+lineio_conn *conn = NULL;
+
+void connected_cb(
+ void *baton, int fd, int ecode, const char *error
+);
+
+void lio_cb(
+ struct lineio_conn *conn, int fd, void *baton,
+ enum lineio_events ev, void *data);
+
int main(void) {
int i;
signal(SIGINT, finish); /* arrange interrupts to terminate */
@@ -32,7 +44,6 @@
move(LINES - 1, 0);
entry_init();
-/* io_init();*/
event_init();
display_init(LINES - 2);
@@ -41,6 +52,7 @@
refresh();
event_addfd(0, EVENT_FD_READABLE | EVENT_FD_ERROR, handle_input, NULL);
+ net_async_connect(connected_cb, NULL, "localhost", 12564);
for (;;) {
int c = event_poll(1);
@@ -54,6 +66,26 @@
exit(0);
}
+void connected_cb(
+ void *baton, int fd, int ecode, const char *error
+)
+{
+ if (fd == -1) {
+ display_print("connect error: %s\n", error);
+ return;
+ }
+ conn = lineio_attach(fd, lio_cb, NULL);
+}
+
+void lio_cb(
+ struct lineio_conn *conn, int fd, void *baton,
+ enum lineio_events ev, void *data)
+{
+ if (ev == LINEIO_GOTLINE) {
+ display_print("INPUT:\n|%s|\n", (char *)data);
+ }
+}
+
void handle_input(int fd, int mode, void *baton) {
int c;
size_t pos, len;
@@ -87,7 +119,13 @@
case KEY_ENTER:
case '\n':
case '\r':
- display_print("%s\n",entry_get());
+ if (conn) {
+ display_print("OUT: %s\n", entry_get());
+ lineio_printf(conn, "%s\n", entry_get());
+ } else {
+ display_print("Not connected.\n");
+ break;
+ }
/* fallthru */
case KEY_DL:
entry_clear();