#include <stdio.h>\r
#include <string.h>\r
#include <net.h>\r
+#include <readline.h>\r
\r
#define BUFSIZ 1023\r
\r
\r
// === PROTOTYPES ===\r
int ParseArguments(int argc, const char *argv[]);\r
-void ProcessIncoming(tServer *Server);\r
+ int ProcessIncoming(tServer *Server);\r
int writef(int FD, const char *Format, ...);\r
int OpenTCP(const char *AddressString, short PortNumber);\r
\r
{\r
int tmp;\r
tServer srv;\r
+ tReadline *readline_info;\r
\r
memset(&srv, 0, sizeof(srv));\r
\r
\r
printf("Processing\n");\r
\r
+ readline_info = Readline_Init(1);\r
+ \r
for( ;; )\r
{\r
fd_set readfds;\r
FD_SET(0, &readfds); // stdin\r
FD_SET(srv.FD, &readfds);\r
\r
- rv = select(srv.FD, &readfds, 0, 0, NULL);\r
+ rv = select(srv.FD+1, &readfds, 0, 0, NULL);\r
if( rv == -1 ) break;\r
\r
if(FD_ISSET(0, &readfds))\r
{\r
// User input\r
+ char *cmd = Readline_NonBlock(readline_info);\r
+ if( cmd )\r
+ {\r
+ // TODO: Implement windows / proper commands, but meh\r
+ if( cmd[0] )\r
+ writef(srv.FD, "%s\n", cmd);\r
+ free(cmd);\r
+ }\r
}\r
\r
// Server response\r
if(FD_ISSET(srv.FD, &readfds))\r
{\r
- ProcessIncoming(&srv);\r
+ if( ProcessIncoming(&srv) != 0 ) {\r
+ // Oops, error\r
+ break;\r
+ }\r
}\r
}\r
\r
/**\r
* \brief Process incoming lines from the server\r
*/\r
-void ProcessIncoming(tServer *Server)\r
+int ProcessIncoming(tServer *Server)\r
{ \r
char *ptr, *newline;\r
int len;\r
#endif\r
// Read data\r
len = read(Server->FD, BUFSIZ - Server->ReadPos, &Server->InBuf[Server->ReadPos]);\r
+ if( len == -1 ) {\r
+ return -1;\r
+ }\r
Server->InBuf[Server->ReadPos + len] = '\0';\r
\r
// Break into lines\r
#if NON_BLOCK_READ\r
}\r
#endif\r
+ \r
+ return 0;\r
}\r
\r
/**\r