Revision: 480
          http://vde.svn.sourceforge.net/vde/?rev=480&view=rev
Author:   rd235
Date:     2011-03-27 09:07:52 +0000 (Sun, 27 Mar 2011)

Log Message:
-----------
Step two towards a new management of packetq: fd->poll structure permutation 
array (O(1) access
                to poll events), endpoint as an opaque identifier for upper 
layers.

Modified Paths:
--------------
    branches/rd235/vde-2/src/vde_switch/consmgmt.c
    branches/rd235/vde-2/src/vde_switch/datasock.c
    branches/rd235/vde-2/src/vde_switch/port.c
    branches/rd235/vde-2/src/vde_switch/port.h
    branches/rd235/vde-2/src/vde_switch/switch.h
    branches/rd235/vde-2/src/vde_switch/tuntap.c
    branches/rd235/vde-2/src/vde_switch/vde_switch.c

Modified: branches/rd235/vde-2/src/vde_switch/consmgmt.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/consmgmt.c      2011-03-25 18:08:57 UTC 
(rev 479)
+++ branches/rd235/vde-2/src/vde_switch/consmgmt.c      2011-03-27 09:07:52 UTC 
(rev 480)
@@ -370,7 +370,7 @@
                return;
        }
 
-       add_fd(new,mgmt_data,-1);
+       add_fd(new,mgmt_data,NULL);
        EVENTOUT(MGMTPORTNEW,new);
        snprintf(buf,MAXCMD,header,PACKAGE_VERSION);
        write(new,buf,strlen(buf));
@@ -381,7 +381,7 @@
 static int debugdel(int fd,char *arg);
 #endif
 static char *EOS="9999 END OF SESSION";
-static void handle_input(unsigned char type,int fd,int revents,int *unused)
+static void handle_input(unsigned char type,int fd,int revents,void 
*private_data)
 {
        char buf[MAXCMD];
        if (type != mgmt_ctl) {
@@ -393,7 +393,7 @@
                                printlog(LOG_WARNING,"Reading from mgmt 
%s",strerror(errno));
                        }
                }
-               if (n==0) { /*EOF*/
+               if (n==0) { /*EOF || POLLHUP*/
                        if (type == console_type) {
                                printlog(LOG_WARNING,"EOF on stdin, cleaning up 
and exiting");
                                exit(0);
@@ -440,7 +440,7 @@
                        return;
                }
 
-               add_fd(new,mgmt_data,-1);
+               add_fd(new,mgmt_data,NULL);
                EVENTOUT(MGMTPORTNEW,new);
                snprintf(buf,MAXCMD,header,PACKAGE_VERSION);
                write(new,buf,strlen(buf));
@@ -478,7 +478,7 @@
        fclose(f);
 }
 
-static void cleanup(unsigned char type,int fd,int arg)
+static void cleanup(unsigned char type,int fd,void *private_data)
 {
        if (fd < 0) {
                if((pidfile != NULL) && unlink(pidfile_path) < 0) {
@@ -572,7 +572,7 @@
        if(isatty(0) && !daemonize)
        {
                console_type=add_type(&swmi,0);
-               add_fd(0,console_type,-1);
+               add_fd(0,console_type,NULL);
        }
 
        /* saves current path in pidfile_path, because otherwise with 
daemonize() we
@@ -625,7 +625,7 @@
                }
                mgmt_ctl=add_type(&swmi,0);
                mgmt_data=add_type(&swmi,0);
-               add_fd(mgmtconnfd,mgmt_ctl,-1);
+               add_fd(mgmtconnfd,mgmt_ctl,NULL);
        }
 }
 

Modified: branches/rd235/vde-2/src/vde_switch/datasock.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/datasock.c      2011-03-25 18:08:57 UTC 
(rev 479)
+++ branches/rd235/vde-2/src/vde_switch/datasock.c      2011-03-27 09:07:52 UTC 
(rev 480)
@@ -106,10 +106,11 @@
                (stat((PATH),&s)?-1:s.st_uid); \
                })
 
-static int new_port_v1_v3(int fd_ctl, int type_port,
+static struct endpoint *new_port_v1_v3(int fd_ctl, int type_port,
                struct sockaddr_un *sun_out)
 {
        int n, portno;
+       struct endpoint *ep;
        enum request_type type = type_port & 0xff;
        int port_request=type_port >> 8;
        uid_t user=-1;
@@ -127,7 +128,7 @@
                        if (sun_out->sun_path[0] != 0) { //not for unnamed 
sockets
                                if (access(sun_out->sun_path,R_OK | W_OK) != 0) 
{ //socket error
                                        remove_fd(fd_ctl);
-                                       return -1;
+                                       return NULL;
                                }
                                user=GETFILEOWNER(sun_out->sun_path);
                        }
@@ -135,13 +136,13 @@
                        if((fd_data = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0){
                                printlog(LOG_ERR,"socket: %s",strerror(errno));
                                remove_fd(fd_ctl);
-                               return -1;
+                               return NULL;
                        }
                        if(fcntl(fd_data, F_SETFL, O_NONBLOCK) < 0){
                                printlog(LOG_ERR,"Setting O_NONBLOCK on data fd 
%s",strerror(errno));
                                close(fd_data);
                                remove_fd(fd_ctl);
-                               return -1;
+                               return NULL;
                        }
 
 #ifdef VDE_DARWIN
@@ -157,23 +158,22 @@
                                printlog(LOG_ERR,"Connecting to client data 
socket %s",strerror(errno));
                                close(fd_data);
                                remove_fd(fd_ctl);
-                               return -1;
+                               return NULL;
                        }
 
-                       portno = setup_ep(port_request, fd_ctl, fd_data, user, 
&modfun); 
-                       add_fd(fd_data,data_type,portno);
-                       if(portno<0) {
-                               close_ep(portno,fd_ctl);
-                               return -1;
-                       }
+                       ep = setup_ep(port_request, fd_ctl, fd_data, user, 
&modfun); 
+                       if(ep == NULL)
+                               return NULL;
+                       portno=ep_get_port(ep);
+                       add_fd(fd_data,data_type,ep);
                        sun_in.sun_family = AF_UNIX;
                        
snprintf(sun_in.sun_path,sizeof(sun_in.sun_path),"%s/%03d.%d",ctl_socket,portno,fd_data);
 
                        if ((unlink(sun_in.sun_path) < 0 && errno != ENOENT) ||
                                        bind(fd_data, (struct sockaddr *) 
&sun_in, sizeof(struct sockaddr_un)) < 0){
                                printlog(LOG_ERR,"Binding to data socket 
%s",strerror(errno));
-                               close_ep(portno,fd_ctl);
-                               return -1;
+                               close_ep(ep);
+                               return NULL;
                        }
                        if (geteuid() != 0)
                                user = -1;
@@ -184,29 +184,30 @@
                        if(chown(sun_in.sun_path,user,grp_owner) < 0) {
                                printlog(LOG_ERR, "chown: %s", strerror(errno));
                                unlink(sun_in.sun_path);
-                               close_ep(portno,fd_ctl);
-                               return -1;
+                               close_ep(ep);
+                               return NULL;
                        }
 
                        n = write(fd_ctl, &sun_in, sizeof(sun_in));
                        if(n != sizeof(sun_in)){
                                printlog(LOG_WARNING,"Sending data socket name 
%s",strerror(errno));
-                               close_ep(portno,fd_ctl);
-                               return -1;
+                               close_ep(ep);
+                               return NULL;
                        }
                        if (type==REQ_NEW_PORT0)
                                setmgmtperm(sun_in.sun_path);
-                       return portno;
+                       return ep;
                        break;
                default:
                        printlog(LOG_WARNING,"Bad request type : %d", type);
                        remove_fd(fd_ctl); 
-                       return -1;
+                       return NULL;
        }
 }
 
-static void handle_input(unsigned char type,int fd,int revents,int *arg)
+static void handle_input(unsigned char type,int fd,int revents,void *arg)
 {
+       struct endpoint *ep=arg;
        if (type == data_type) {
                struct bipacket packet;
                int len;
@@ -219,7 +220,7 @@
                else if(len == 0) 
                        printlog(LOG_WARNING,"EOF data port: 
%s",strerror(errno));
                else if(len >= ETH_HEADER_SIZE)
-                       handle_in_packet(*arg, &(packet.p), len);
+                       handle_in_packet(ep, &(packet.p), len);
        }
        else if (type == wd_type) {
                char reqbuf[REQBUFLEN+1];
@@ -236,12 +237,11 @@
                } else if (len > 0) {
                        reqbuf[len]=0;
                        if(req->v1.magic == SWITCH_MAGIC){
-                               int port=-1;
                                if(req->v3.version == 3) {
-                                       port=new_port_v1_v3(fd, req->v3.type, 
&(req->v3.sock));
-                                       if (port>=0) {
-                                               *arg=port;
-                                               
setup_description(*arg,fd,strdup(req->v3.description));
+                                       ep=new_port_v1_v3(fd, req->v3.type, 
&(req->v3.sock));
+                                       if (ep != NULL) {
+                                               
mainloop_set_private_data(fd,ep);
+                                               
setup_description(ep,strdup(req->v3.description));
                                        }
                                }
                                else if(req->v3.version > 2 || req->v3.version 
== 2) {
@@ -250,8 +250,11 @@
                                        remove_fd(fd); 
                                }
                                else {
-                                       *arg=port=new_port_v1_v3(fd, 
req->v1.type, &(req->v1.u.new_control.name));
-                                       
setup_description(*arg,fd,strdup(req->v1.description));
+                                       ep=new_port_v1_v3(fd, req->v1.type, 
&(req->v1.u.new_control.name));
+                                       if (ep != NULL) {
+                                               
mainloop_set_private_data(fd,ep);
+                                               
setup_description(ep,strdup(req->v1.description));
+                                       }
                                }
                        }
                        else {
@@ -260,8 +263,8 @@
                                return;
                        }
                } else {
-                       if (*arg >= 0)
-                               close_ep(*arg,fd);
+                       if (ep != NULL)
+                               close_ep(ep);
                        else
                                remove_fd(fd);
                }
@@ -284,11 +287,11 @@
                        return;
                }*/
 
-               add_fd(new,wd_type,-1);
+               add_fd(new,wd_type,NULL);
        }
 }
 
-static void cleanup(unsigned char type,int fd,int arg)
+static void cleanup(unsigned char type,int fd,void *arg)
 {
        struct sockaddr_un clun;
        int test_fd;
@@ -312,8 +315,9 @@
                }
                else printlog(LOG_WARNING,"Cleanup not removing files");
        } else {
-               if (type == data_type && arg>=0) {
-                       
snprintf(clun.sun_path,sizeof(clun.sun_path),"%s/%03d.%d",ctl_socket,arg,fd);
+               if (type == data_type && arg != NULL) {
+                       int portno=ep_get_port(arg);
+                       
snprintf(clun.sun_path,sizeof(clun.sun_path),"%s/%03d.%d",ctl_socket,portno,fd);
                        unlink(clun.sun_path);
                }
                close(fd);
@@ -470,7 +474,7 @@
        ctl_type=add_type(&swmi,0);
        wd_type=add_type(&swmi,0);
        data_type=add_type(&swmi,1);
-       add_fd(connect_fd,ctl_type,-1);
+       add_fd(connect_fd,ctl_type,NULL);
 }
 
 static int showinfo(FILE *fd)

Modified: branches/rd235/vde-2/src/vde_switch/port.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/port.c  2011-03-25 18:08:57 UTC (rev 
479)
+++ branches/rd235/vde-2/src/vde_switch/port.c  2011-03-27 09:07:52 UTC (rev 
480)
@@ -231,11 +231,8 @@
        }
 }
 
-/* initialize a port structure with control=fd, given data+data_len and sender
- * function; 
- * and then add it to the g_fdsdata array at index i. */
-int setup_ep(int portno, int fd_ctl, int fd_data,
-               uid_t user,
+/* initialize a new endpoint */
+struct endpoint *setup_ep(int portno, int fd_ctl, int fd_data, uid_t user,
                struct mod_support *modfun)
 {
        struct port *port;
@@ -277,38 +274,34 @@
                                ep->next=port->ep;
                                port->ep=ep;
                        }
-                       return portno;
+                       return ep;
                }
                else {
                        if (port->curuser != user)
                                errno=EADDRINUSE;
                        else 
                                errno=ENOMEM;
-                       return -1;
+                       return NULL;
                }
        }
        else {
                errno=ENOMEM;
-               return -1;
+               return NULL;
        }
 }
 
-void setup_description(int portno, int fd_ctl, char *descr)
+int ep_get_port(struct endpoint *ep)
 {
-       if (portno >=0 && portno < numports) {
-               struct port *port=portv[portno];
-               if (port != NULL) {
-                       struct endpoint *ep;
-                       for (ep=port->ep;ep!=NULL;ep=ep->next) 
-                               if (ep->fd_ctl == fd_ctl) {
-                                       DBGOUT(DBGPORTDESCR,"Port %02d FD %2d 
-> \"%s\"",portno,fd_ctl,descr);
-                                       
EVENTOUT(DBGPORTDESCR,portno,fd_ctl,descr);
-                                       ep->descr=descr;
-                               }
-               }
-       }
+       return ep->port;
 }
 
+void setup_description(struct endpoint *ep, char *descr)
+{
+       DBGOUT(DBGPORTDESCR,"Port %02d FD %2d -> 
\"%s\"",ep->port,ep->fd_ctl,descr);
+       EVENTOUT(DBGPORTDESCR,ep->port,ep->fd_ctl,descr);
+       ep->descr=descr;
+}
+
 static int rec_close_ep(struct endpoint **pep, int fd_ctl)
 {
        struct endpoint *this=*pep;
@@ -330,7 +323,7 @@
                return ENXIO;
 }
 
-int close_ep(int portno, int fd_ctl)
+static int close_ep_port_fd(int portno, int fd_ctl)
 {
        if (portno >=0 && portno < numports) {
                struct port *port=portv[portno];
@@ -340,9 +333,6 @@
                                DBGOUT(DBGPORTDEL,"%02d",portno);
                                EVENTOUT(DBGPORTDEL,portno);
                                hash_delete_port(portno);
-                               /*if (portv[portno]->ms->delport)
-                                       
portv[portno]->ms->delport(port->fd_data,portno);
-                               port->fd_data=-1;*/
                                port->ms=NULL;
                                port->sender=NULL;
                                port->curuser=-1;
@@ -363,6 +353,11 @@
                return EINVAL;
 }
 
+int close_ep(struct endpoint *ep)
+{
+       return close_ep_port_fd(ep->port, ep->fd_ctl);
+}
+
 int portflag(int op,int f)
 {
        int oldflag=pflag;
@@ -508,10 +503,11 @@
         (struct packet *)((char *)(P)-4); })
 
 
-void handle_in_packet(int port,  struct packet *packet, int len)
+void handle_in_packet(struct endpoint *ep,  struct packet *packet, int len)
 {
        int tarport;
        int vlan,tagged;
+       int port=ep->port;
 
        if(PACKETFILTER(PKTFILTIN,port,packet,len)) {
 
@@ -781,7 +777,7 @@
        if (sscanf(arg,"%i %i",&port,&id) != 2)
                return EINVAL;
        else
-               return close_ep(port,id);
+               return close_ep_port_fd(port,id);
 }
 
 static char *port_getuser(uid_t uid)

Modified: branches/rd235/vde-2/src/vde_switch/port.h
===================================================================
--- branches/rd235/vde-2/src/vde_switch/port.h  2011-03-25 18:08:57 UTC (rev 
479)
+++ branches/rd235/vde-2/src/vde_switch/port.h  2011-03-27 09:07:52 UTC (rev 
480)
@@ -35,25 +35,27 @@
 #define psetcfi(X,V)  ((X)[0]= ((X)[0] & 0xef) | (V&1)<<4)
 #define psetvlan(X,V) ({(X)[1]=(V)&0xff;(X)[0]=((X)[0] & 0xf0) | ((V)>>8) & 
0xf; (V); })
 
+struct endpoint;
+
 struct mod_support {
        char *modname;
        int (*sender)(int fd_ctl, int fd_data, void *packet, int len, int port);
-//     int (*newport)(int fd_ctl,int portno,uid_t user);
        void (*delep)(int fd_ctl, int fd_data, void *descr);
-//     void (*delport)(int fd,int portno);
 };
 
-extern int setup_ep(int portno, int fd_ctl,
+extern struct endpoint *setup_ep(int portno, int fd_ctl,
                int fd_data,
                uid_t user,
                struct mod_support *modfun);
 
-extern void setup_description(int portno, int fd_ctl, char *descr);
+extern int ep_get_port(struct endpoint *ep);
 
-extern int close_ep(int portno, int fd_ctl);
+extern void setup_description(struct endpoint *ep, char *descr);
 
-extern void handle_in_packet(int port, struct packet *packet, int len);
+extern int close_ep(struct endpoint *ep);
 
+extern void handle_in_packet(struct endpoint *ep, struct packet *packet, int 
len);
+
 extern bitarray validvlan;
 int portflag(int op, int f);
 #define P_GETFLAG 0

Modified: branches/rd235/vde-2/src/vde_switch/switch.h
===================================================================
--- branches/rd235/vde-2/src/vde_switch/switch.h        2011-03-25 18:08:57 UTC 
(rev 479)
+++ branches/rd235/vde-2/src/vde_switch/switch.h        2011-03-27 09:07:52 UTC 
(rev 480)
@@ -36,8 +36,8 @@
        void (*usage)(void); /* usage function: command line opts explanation */
        int (*parseopt)(int parm,char *optarg); /* parse getopt output */
        void (*init)(void); /* init */
-       void (*handle_input)(unsigned char type,int fd,int revents,int *arg); 
/* handle input */
-       void (*cleanup)(unsigned char type,int fd,int arg); /*cleanup for files 
or final if fd == -1 */
+       void (*handle_input)(unsigned char type,int fd,int revents,void 
*private_data); /* handle input */
+       void (*cleanup)(unsigned char type,int fd,void *private_data); 
/*cleanup for files or final if fd == -1 */
        struct swmodule *next;
 };
 
@@ -45,8 +45,14 @@
 void del_swm(struct swmodule *old);
 unsigned char add_type(struct swmodule *mgr,int prio);
 void del_type(unsigned char type);
-void add_fd(int fd,unsigned char type,int arg);
+void add_fd(int fd,unsigned char type,void *private_data);
 void remove_fd(int fd);
+void *mainloop_get_private_data(int fd);
+void mainloop_set_private_data(int fd,void *private_data);
+short mainloop_pollmask_get(int fd);
+void mainloop_pollmask_add(int fd, short events);
+void mainloop_pollmask_del(int fd, short events);
+void mainloop_pollmask_set(int fd, short events);
 
 #define STDRCFILE "/etc/vde2/vde_switch.rc"
 

Modified: branches/rd235/vde-2/src/vde_switch/tuntap.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/tuntap.c        2011-03-25 18:08:57 UTC 
(rev 479)
+++ branches/rd235/vde-2/src/vde_switch/tuntap.c        2011-03-27 09:07:52 UTC 
(rev 480)
@@ -71,8 +71,9 @@
        return 0;
 }
 
-static void handle_input(unsigned char type,int fd,int revents,int *arg)
+static void handle_input(unsigned char type,int fd,int revents,void 
*private_data)
 {
+       struct endpoint *ep=private_data;
        struct bipacket packet;
        int len=read(fd, &(packet.p), sizeof(struct packet));
 
@@ -85,11 +86,11 @@
                        printlog(LOG_WARNING,"EOF tap data port: 
%s",strerror(errno));
                /* close tap! */
        } else if (len >= ETH_HEADER_SIZE)
-               handle_in_packet(*arg, &(packet.p), len);
+               handle_in_packet(ep, &(packet.p), len);
 }
 
 
-static void cleanup(unsigned char type,int fd,int arg)
+static void cleanup(unsigned char type,int fd,void *private_data)
 {
        if (fd >= 0)
                close(fd);
@@ -208,20 +209,19 @@
 }
 #endif
 
-static int newtap(char *dev)
+static struct endpoint *newtap(char *dev)
 {
        int tap_fd;
        tap_fd = open_tap(dev);
        if (tap_fd>0) {
-               int portno=setup_ep(0,tap_fd,tap_fd,-1,&modfun);
-               if (portno >= 0) {
-                       setup_description(portno,tap_fd,dev);
-                       add_fd(tap_fd,tap_type,portno);
-                       return portno;
-               } else 
-                       return -1;
+               struct endpoint *ep=setup_ep(0,tap_fd,tap_fd,-1,&modfun);
+               if (ep != NULL) {
+                       setup_description(ep,dev);
+                       add_fd(tap_fd,tap_type,ep);
+               } 
+               return ep;
        } else
-               return -1;
+               return NULL;
 }
 
 static void init(void)
@@ -230,7 +230,7 @@
                struct init_tap *p;
                tap_type=add_type(&swmi,1);
                for(p=hinit_tap;p != NULL;p=p->next) {
-                       if (newtap(p->tap_dev) < 0)
+                       if (newtap(p->tap_dev) == NULL)
                                printlog(LOG_ERR,"ERROR OPENING tap interface: 
%s",p->tap_dev);
                }
                hinit_tap=free_init_tap(hinit_tap);

Modified: branches/rd235/vde-2/src/vde_switch/vde_switch.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/vde_switch.c    2011-03-25 18:08:57 UTC 
(rev 479)
+++ branches/rd235/vde-2/src/vde_switch/vde_switch.c    2011-03-27 09:07:52 UTC 
(rev 480)
@@ -87,15 +87,23 @@
 /* FD MGMT */
 struct pollplus {
        unsigned char type;
-       int arg;
+       void *private_data;
        time_t timestamp;
 };
 
+#define MAXFDS_INITIAL 8
+#define MAXFDS_STEP 16
 static int nfds = 0;
 static int nprio =0;
 static struct pollfd *fds = NULL;
 static struct pollplus **fdpp = NULL;
 
+/* permutation array: it maps each fd to its index in fds/fdpp */
+/* fdpermsize is a multiple of 16 */
+#define FDPERMSIZE_LOGSTEP 4
+static short *fdperm;
+static int fdpermsize=0;
+
 static int maxfds = 0;
 
 static struct swmodule **fdtypes;
@@ -139,13 +147,13 @@
        ntypes--;
 }
 
-void add_fd(int fd,unsigned char type,int arg)
+void add_fd(int fd,unsigned char type,void *private_data)
 {
        struct pollfd *p;
        int index;
-       /* enlarge fds and g_fdsdata array if needed */
+       /* enlarge fds and fdpp array if needed */
        if(nfds == maxfds){
-               maxfds = maxfds ? 2 * maxfds : 8;
+               maxfds = maxfds ? maxfds + MAXFDS_STEP : MAXFDS_INITIAL;
                if((fds = realloc(fds, maxfds * sizeof(struct pollfd))) == 
NULL){
                        printlog(LOG_ERR,"realloc fds %s",strerror(errno));
                        exit(1);
@@ -155,6 +163,13 @@
                        exit(1);
                }
        }
+       if (fd >= fdpermsize) {
+               fdpermsize = ((fd >> FDPERMSIZE_LOGSTEP) + 1) << 
FDPERMSIZE_LOGSTEP;
+               if((fdperm = realloc(fdperm, fdpermsize * sizeof(short))) == 
NULL){
+                       printlog(LOG_ERR,"realloc fdperm %s",strerror(errno));
+                       exit(1);
+               }
+       }
        if (ISPRIO(type)) {
                fds[nfds]=fds[nprio];
                fdpp[nfds]=fdpp[nprio];
@@ -166,11 +181,12 @@
                printlog(LOG_ERR,"realloc pollplus elem %s",strerror(errno));
                exit(1);
        }
+       fdperm[fd]=index;
        p = &fds[index];
        p->fd = fd;
        p->events = POLLIN | POLLHUP;
        fdpp[index]->type=type;
-       fdpp[index]->arg=arg;
+       fdpp[index]->private_data=private_data;
        nfds++;
 }
 
@@ -178,7 +194,7 @@
 {
        register int i;
        for(i = 0; i < nfds; i++)
-               
TYPE2MGR(fdpp[i]->type)->cleanup(fdpp[i]->type,fds[i].fd,fdpp[i]->arg);
+               
TYPE2MGR(fdpp[i]->type)->cleanup(fdpp[i]->type,fds[i].fd,fdpp[i]->private_data);
 }
 
 void remove_fd(int fd)
@@ -192,16 +208,52 @@
                printlog(LOG_WARNING,"remove_fd : Couldn't find descriptor %d", 
fd);
        } else {
                struct pollplus *old=fdpp[i];
-               
TYPE2MGR(fdpp[i]->type)->cleanup(fdpp[i]->type,fds[i].fd,fdpp[i]->arg);
+               
TYPE2MGR(fdpp[i]->type)->cleanup(fdpp[i]->type,fds[i].fd,fdpp[i]->private_data);
                if (ISPRIO(fdpp[i]->type)) nprio--;
-               memmove(&fds[i], &fds[i + 1], (maxfds - i - 1) * sizeof(struct 
pollfd));
-               memmove(&fdpp[i], &fdpp[i + 1], (maxfds - i - 1) * 
sizeof(struct pollplus *));
+               memmove(&fds[i], &fds[i + 1], (nfds - i - 1) * sizeof(struct 
pollfd));
+               memmove(&fdpp[i], &fdpp[i + 1], (nfds - i - 1) * sizeof(struct 
pollplus *));
+               for(;i<nfds;i++)
+                       fdperm[fds[i].fd]=i;
                free(old);
                nfds--;
        }
 }
 
+/* read/update events/private_data */
+void *mainloop_get_private_data(int fd)
+{
+       if (fd >= 0 && fd < fdpermsize)
+               return (fdpp[fdperm[fd]]->private_data);
+       else
+               return NULL;
+}
 
+void mainloop_set_private_data(int fd,void *private_data)
+{
+       if (fd >=0  && fd < fdpermsize)
+               fdpp[fdperm[fd]]->private_data = private_data;
+}
+
+short mainloop_pollmask_get(int fd)
+{
+       return fds[fdperm[fd]].events;
+}
+
+void mainloop_pollmask_add(int fd, short events)
+{
+       fds[fdperm[fd]].events |= events;
+}
+
+void mainloop_pollmask_del(int fd, short events)
+{
+       fds[fdperm[fd]].events &= ~events;
+}
+
+void mainloop_pollmask_set(int fd, short events)
+{
+       fds[fdperm[fd]].events = events;
+}
+
 static void main_loop()
 {
        time_t now;
@@ -226,7 +278,7 @@
                                        register int prenfds=nfds;
                                        n--;
                                        fdpp[i]->timestamp=now;
-                                       
TYPE2MGR(fdpp[i]->type)->handle_input(fdpp[i]->type,fds[i].fd,fds[i].revents,&(fdpp[i]->arg));
+                                       
TYPE2MGR(fdpp[i]->type)->handle_input(fdpp[i]->type,fds[i].fd,fds[i].revents,fdpp[i]->private_data);
                                        if (nfds!=prenfds) /* the current fd 
has been deleted */
                                                break; /* PERFORMANCE it is 
faster returning to poll */
                                }       
@@ -241,6 +293,8 @@
                                                        struct pollplus *tfdpp;
                                                        
tfds=fds[i];fds[i]=fds[i_1];fds[i_1]=tfds;
                                                        
tfdpp=fdpp[i];fdpp[i]=fdpp[i_1];fdpp[i_1]=tfdpp;
+                                                       fdperm[fds[i].fd]=i;
+                                                       fdperm[fds[i_1].fd]=i_1;
                                                }
                                        }
                                }
@@ -292,7 +346,7 @@
 { 
        printf(
                        "VDE " PACKAGE_VERSION "\n"
-                       "Copyright 2003,2004,2005 Renzo Davoli\n"
+                       "Copyright 2003,...,2011 Renzo Davoli\n"
                        "some code from uml_switch Copyright (C) 2001, 2002 
Jeff Dike and others\n"
                        "VDE comes with NO WARRANTY, to the extent permitted by 
law.\n"
                        "You may redistribute copies of VDE under the terms of 
the\n"
@@ -470,7 +524,7 @@
        file_cleanup();
        for(swmp=swmh;swmp != NULL;swmp=swmp->next)
                if (swmp->cleanup != NULL)
-                       swmp->cleanup(0,-1,-1);
+                       swmp->cleanup(0,-1,NULL);
 }
 
 static void sig_handler(int sig)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
vde-users mailing list
vde-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vde-users

Reply via email to