dev/net: shutdown hooks
authorAlan Cox <alan@linux.intel.com>
Fri, 25 Mar 2016 20:49:54 +0000 (20:49 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 25 Mar 2016 20:49:54 +0000 (20:49 +0000)
Kernel/dev/net/net_at.c
Kernel/dev/net/net_native.c
Kernel/dev/net/net_z80pack.c

index 82041e6..0995774 100644 (file)
@@ -185,10 +185,12 @@ arg_t net_read(struct socket *s, uint8_t flag)
     }
     
     while(netat_ready() && n < udata.u_count) {
+      if (s->s_iflag & SI_SHUTR)
+        break;
       uputc(netat_byte(), udata.u_base++);
       n++;
     }
-    if (n)
+    if (n || (s->s_iflag & SI_SHUTR))
       return n;
     s->s_iflag &= ~SI_DATA;
     netat_wake();
@@ -207,7 +209,7 @@ arg_t net_write(struct socket *s, uint8_t flag)
   used(flag);
 
   while(n < udata.u_count) {
-    if (sockets[0].s_state == SS_CLOSED) {
+    if (sockets[0].s_state == SS_CLOSED || (sockets[0].s_iflag & SI_SHUTW)) {
       udata.u_error = EPIPE;
       ssig(udata.u_ptab, SIGPIPE);
       return -1;
@@ -219,6 +221,13 @@ arg_t net_write(struct socket *s, uint8_t flag)
   return udata.u_count;
 }
 
+arg_t net_shutdown(struct socket *s, uint8_t flag)
+{
+  s->s_iflag |= flag;
+  netat_wake();
+  return 0;
+}
+
 struct netdevice net_dev = {
   0,
   "at0",
index 5c7514b..2db6479 100644 (file)
@@ -471,7 +471,7 @@ arg_t net_read(struct socket *s, uint8_t flag)
                        n = netn_copyout(s);
                if (n == 0xFFFF)
                        return -1;
-               if (n)
+               if (n || (s->s_iflag & SI_SHUTR))
                        return n;
                s->s_iflag &= ~SI_DATA;
                /* Could do with using timeouts here to be clever for non O_NDELAY so
@@ -497,7 +497,7 @@ arg_t net_write(struct socket * s, uint8_t flag)
        }
 
        while (t < udata.u_count) {
-               if (s->s_state == SS_CLOSED) {
+               if (s->s_state == SS_CLOSED || (s->s_iflag & SI_SHUTW)) {
                        udata.u_error = EPIPE;
                        ssig(udata.u_ptab, SIGPIPE);
                        return -1;
@@ -521,6 +521,13 @@ arg_t net_write(struct socket * s, uint8_t flag)
        return udata.u_count;
 }
 
+arg_t net_shutdown(struct socket *s, uint8-t flag)
+{
+       s->s_iflag |= flag;
+       wakeup_all(s);
+       return 0;
+}
+
 /* Gunk we are still making up */
 struct netdevice net_dev = {
        0,
index 964206f..a3712a5 100644 (file)
@@ -288,8 +288,10 @@ arg_t net_write(struct socket * s, uint8_t flag)
                netstat = s->s_num;
                st = status(s);
 
-               if (s->s_state == SS_CLOSED)
+               if (s->s_state == SS_CLOSED || (s->s_iflag & SI_SHUTW)) {
+                       udata.u_error = EPIPE;
                        break;
+                }
 
                /* Error or EOF */
                if (st & 0xC0)
@@ -321,14 +323,24 @@ arg_t net_write(struct socket * s, uint8_t flag)
        }
        /* It broke mummy ! */
         irqrestore(irq);
-       if (n)
+       if (n) {
+               s->s_error = udata.u_error;
+               udata.u_error = 0;
                return n;
+        }
        err_xlate(s);
        if (udata.u_error == EPIPE)
                ssig(udata.u_ptab, SIGPIPE);
        return -1;
 }
 
+arg_t net_shutdown(struct socket *s, uint8_t flag)
+{
+        s->s_iflag |= flag;
+        wakeup_all(s);
+        return 0;
+}
+
 /* Gunk we are still making up */
 struct netdevice net_dev = {
        0,