net_native: implement new callback behaviour
authorAlan Cox <alan@linux.intel.com>
Fri, 30 Mar 2018 23:27:03 +0000 (00:27 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 30 Mar 2018 23:27:03 +0000 (00:27 +0100)
We sendd a new UNHOOK message to the netd stack and when it replies to say
it's done the job we tell the kernel it can recycle the socket.

Kernel/dev/net/net_native.c
Kernel/include/net_native.h

index d0e3767..4ebf8a3 100644 (file)
@@ -95,6 +95,12 @@ int netdev_write(uint8_t flags)
                        s->s_error = ne.ret;
                wakeup_all(s);
                break;
+       case NE_UNHOOK:
+               if (s->s_state == SS_DEAD)
+                       sock_closed(s);
+               else
+                       kputs("bad unhook (in use)\n");
+               break;
        default:
                kprintf("netbad %d\n", ne.event);
                udata.u_error = EOPNOTSUPP;
@@ -225,7 +231,8 @@ static int netn_synchronous_event(struct socket *s, uint8_t state)
        selwake_dev(4, 65, SELECT_IN);
 
        do {
-           if( s->s_state == SS_CLOSED )
+           kprintf("Wait %d in %d\n", state, s->s_state);
+           if( s->s_state == SS_CLOSED || s->s_state == SS_DEAD)
                return -1;
            psleep_nosig(s);
        } while (sd->event & NEVW_STATE);
@@ -442,7 +449,6 @@ static uint16_t netn_copyout(struct socket *s)
  */
 int net_init(struct socket *s)
 {
-    int x;
        struct sockdata *sd = sockdata + s->s_num;
        if (!net_ino) {
                udata.u_error = ENETDOWN;
@@ -494,15 +500,19 @@ int net_connect(struct socket *s)
  *     implementation has longer lived resources (eg a TCP port moving
  *     into TIME_WAIT) then the socket and internal resources must be
  *     disconnected from one another.
+ *
+ *     Fuzix close() methods are not permitted to block.
  */
 void net_close(struct socket *s)
 {
        struct sockdata *sd = s->s_priv;
        /* Caution here - the native tcp socket will hang around longer */
-       sd->newstate = SS_CLOSED;
+       sd->newstate = SS_DEAD;
        netn_asynchronous_event(s, NEV_STATE|NEVW_STATE);
-       /* Don't block. We won't reuse the entry until it moves to
-          CLOSED state */
+       /* The stack will see the closed state and then we will
+          progress to SS_DEAD. When the stack is finished with us it
+          will send an UNHOOK message which will do the final resource
+          clean up and allow the socket to be reused */
 }
 
 /*
index a0f00b6..46c149e 100644 (file)
@@ -51,6 +51,7 @@ struct sockmsg {
 #define NE_DATA                6
 #define NE_SHUTR        7
 #define NE_RESET        8
+#define NE_UNHOOK      9
 
 struct netevent {
        uint8_t socket;