[mw-devel] MW3 r1267 - in trunk/src: . webclient
arthur at sucs.org
arthur at sucs.org
Mon Nov 5 10:07:34 GMT 2012
Author: arthur
Date: 2012-11-05 10:07:34 +0000 (Mon, 05 Nov 2012)
New Revision: 1267
Modified:
trunk/src/incoming.c
trunk/src/socket.c
trunk/src/socket.h
trunk/src/webclient/Makefile
trunk/src/webclient/comms.c
Log:
port mwpoll to client-server model as well
Modified: trunk/src/incoming.c
===================================================================
--- trunk/src/incoming.c 2012-11-04 00:53:27 UTC (rev 1266)
+++ trunk/src/incoming.c 2012-11-05 10:07:34 UTC (rev 1267)
@@ -435,20 +435,9 @@
void handle_mesg()
{
- static uint32_t mesg_pid;
long mesg_posn;
static struct person mesg_user;
- int fl;
-
- int nos,i;
- char buff[MAXTEXTLENGTH];
static char newbuff[MAXPIPELENGTH];
- static char pidbuff[4];
- static int ptr=0;
- static int pidp=0;
- static int midread = 0;
- static int quotemode=0;
- enum ipc_types msgtype = IPC_NOOP;
mesg_waiting = 0;
Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c 2012-11-04 00:53:27 UTC (rev 1266)
+++ trunk/src/socket.c 2012-11-05 10:07:34 UTC (rev 1267)
@@ -8,8 +8,6 @@
#include <netdb.h>
#include "socket.h"
-#define _MIN(a,b) (a<b)?a:b
-
inline unsigned int FOURCC(char *a)
{
return ((a[3]<<24)|(a[2]<<16)|(a[1]<<8)|a[0]);
Modified: trunk/src/socket.h
===================================================================
--- trunk/src/socket.h 2012-11-04 00:53:27 UTC (rev 1266)
+++ trunk/src/socket.h 2012-11-05 10:07:34 UTC (rev 1267)
@@ -44,6 +44,8 @@
} ipc_connection_t;
+#define _MIN(a,b) (a<b)?a:b
+
unsigned int FOURCC(char *a);
/* socket.c */
ipc_message_t *ipcmsg_create(uint32_t type,uint32_t src);
Modified: trunk/src/webclient/Makefile
===================================================================
--- trunk/src/webclient/Makefile 2012-11-04 00:53:27 UTC (rev 1266)
+++ trunk/src/webclient/Makefile 2012-11-05 10:07:34 UTC (rev 1267)
@@ -49,7 +49,7 @@
.PHONY: build install clean test
-mwpoll: mwpoll.o import.o comms.o mwstring.o ../perms.o ../strings.o ../files.o ../ipc.o ../iconv.o ../special.o
+mwpoll: mwpoll.o import.o comms.o mwstring.o ../perms.o ../strings.o ../files.o ../ipc.o ../iconv.o ../special.o ../socket.o
$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
clean:
Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c 2012-11-04 00:53:27 UTC (rev 1266)
+++ trunk/src/webclient/comms.c 2012-11-05 10:07:34 UTC (rev 1267)
@@ -24,6 +24,8 @@
#include "comms.h"
#include "list.h"
#include "mwstring.h"
+#include "../socket.h"
+#include "../ipc.h"
extern int incoming_pipe;
int command_sock;
@@ -183,6 +185,7 @@
int ret;
int select_error;
struct list_head *pos, *q;
+ int incoming_pipe = ipc_getfd();
FD_ZERO(&readfds);
FD_ZERO(&exceptfds);
@@ -552,72 +555,30 @@
return 0;
}
+extern ipc_connection_t * ipcsock;
+
static void handle_mesg()
{
- static uint32_t mesg_pid;
long mesg_posn;
static struct person mesg_user;
- int fl;
- int nos,i;
- char buff[MAXTEXTLENGTH];
- static char newbuff[MAXPIPELENGTH];
- static char pidbuff[4];
- static int ptr=0;
- static int pidp=0;
- static int midread = 0;
- static int quotemode=0;
- enum ipc_types msgtype = IPC_NOOP;
+ char newbuff[MAXPIPELENGTH];
- fl = fcntl(incoming_pipe, F_GETFL);
- fcntl(incoming_pipe, F_SETFL, fl | O_NDELAY);
+ ipc_message_t * msg = read_socket(ipcsock, 1);
- while ((nos=read(incoming_pipe,buff,MAXTEXTLENGTH))>0)
- {
- for (i = 0; i < nos; i++) {
- if (! midread) {
- midread = 1;
- msgtype = buff[i];
- if (ptr>0) /* discard partial message */
- printf("\n*** handle_mesg: discarded %d chars.\n\007", ptr);
- pidp=0;
- } else {
- if (pidp<4) {
- pidbuff[pidp] = buff[i];
- pidp++;
- if (pidp>=4) {
- memcpy(&mesg_pid, &pidbuff, 4);
- if ((mesg_posn=get_who_userposn(mesg_pid))<0)
- strcpy(mesg_user.name,"System");
- else
- fetch_user(&mesg_user, mesg_posn);
- ptr=0;
- }
- continue;
- }
- if (! quotemode) {
- if (buff[i] == 1) {
- quotemode = 1;
- continue;
- } else if (buff[i] == '|') {
- newbuff[ptr] = 0;
- accept_pipe_cmd(msgtype, newbuff, mesg_pid, &mesg_user);
- ptr = 0;
- midread = 0;
- continue;
- }
- }
- /* just another character, buffer it for now */
- if (ptr < MAXPIPELENGTH)
- {
- newbuff[ptr]=buff[i];
- ptr++;
- }
- quotemode=0;
- }
- }
+ while (msg != NULL) {
+ if ((mesg_posn=get_who_userposn(msg->head.src))<0)
+ strcpy(mesg_user.name,"System");
+ else
+ fetch_user(&mesg_user, mesg_posn);
+ bzero(newbuff, sizeof(newbuff));
+ memcpy(newbuff, msg->body, _MIN(sizeof(newbuff)-1, msg->bodylen));
+ accept_pipe_cmd(msg->head.type, newbuff, msg->head.src, &mesg_user);
+
+ ipcmsg_destroy(msg);
+ msg = read_socket(ipcsock, 0);
}
- fcntl(incoming_pipe, F_SETFL, fl);
+
}
void close_cmd(void)
More information about the mw-devel
mailing list