resource-related stuff removed from ws transport

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
diff --git a/src/transports/ws/aws.c b/src/transports/ws/aws.c
index 5a64b94..89a9ae5 100644
--- a/src/transports/ws/aws.c
+++ b/src/transports/ws/aws.c
@@ -213,8 +213,7 @@
 
                 /*  Start the sws state machine. */
                 nn_usock_activate (&aws->usock);
-                nn_sws_start (&aws->sws, &aws->usock, NN_WS_SERVER,
-                    NULL, NULL);
+                nn_sws_start (&aws->sws, &aws->usock, NN_WS_SERVER, NULL);
                 aws->state = NN_AWS_STATE_ACTIVE;
 
                 nn_epbase_stat_increment (aws->epbase,
diff --git a/src/transports/ws/cws.c b/src/transports/ws/cws.c
index fbfe49c..2046e93 100644
--- a/src/transports/ws/cws.c
+++ b/src/transports/ws/cws.c
@@ -90,7 +90,6 @@
     struct nn_sws sws;
 
     /*  Parsed parts of the connection URI. */
-    struct nn_chunkref resource;
     struct nn_chunkref remote_host;
     struct nn_chunkref nic;
     int remote_port;
@@ -132,9 +131,7 @@
     const char *hostname;
     size_t hostlen;
     const char *colon;
-    const char *slash;
-    const char *resource;
-    size_t resourcelen;
+    const char *end;
     struct sockaddr_storage ss;
     size_t sslen;
     int ipv4only;
@@ -163,25 +160,22 @@
     semicolon = strchr (addr, ';');
     hostname = semicolon ? semicolon + 1 : addr;
     colon = strrchr (addr, ':');
-    slash = colon ? strchr (colon, '/') : strchr (addr, '/');
-    resource = slash ? slash : addr + addrlen;
-    self->remote_hostname_len = colon ? colon - hostname : resource - hostname;
+    end = addr + strlen (addr);
+    self->remote_hostname_len = colon ? colon - hostname : end - hostname;
     
     /*  Host contains both hostname and port. */
-    hostlen = resource - hostname;
+    hostlen = end - hostname;
 
     /*  Parse the port; assume port 80 if not explicitly declared. */
+    self->remote_port = 80;
     if (nn_slow (colon != NULL)) {
-        rc = nn_port_resolve (colon + 1, resource - colon - 1);
+        rc = nn_port_resolve (colon + 1, end - colon - 1);
         if (nn_slow (rc < 0)) {
             nn_epbase_term (&self->epbase);
             return -EINVAL;
         }
         self->remote_port = rc;
     }
-    else {
-        self->remote_port = 80;
-    }
 
     /*  Check whether the host portion of the address is either a literal
         or a valid hostname. */
@@ -216,19 +210,6 @@
         memcpy (nn_chunkref_data (&self->nic), "*", 1);
     }
 
-    /*  The requested resource is used in opening handshake. */
-    resourcelen = strlen (resource);
-    if (resourcelen) {
-        nn_chunkref_init (&self->resource, resourcelen + 1);
-        strncpy (nn_chunkref_data (&self->resource),
-            resource, resourcelen + 1);
-    }
-    else {
-        /*  No resource specified, so allocate base path. */
-        nn_chunkref_init (&self->resource, 2);
-        strncpy (nn_chunkref_data (&self->resource), "/", 2);
-    }
-
     /*  Initialise the structure. */
     nn_fsm_init_root (&self->fsm, nn_cws_handler, nn_cws_shutdown,
         nn_epbase_getctx (&self->epbase));
@@ -273,7 +254,6 @@
 
     cws = nn_cont (self, struct nn_cws, epbase);
 
-    nn_chunkref_term (&cws->resource);
     nn_chunkref_term (&cws->remote_host);
     nn_chunkref_term (&cws->nic);
     nn_dns_term (&cws->dns);
@@ -410,7 +390,6 @@
             switch (type) {
             case NN_USOCK_CONNECTED:
                 nn_sws_start (&cws->sws, &cws->usock, NN_WS_CLIENT,
-                    nn_chunkref_data (&cws->resource),
                     nn_chunkref_data (&cws->remote_host));
                 cws->state = NN_CWS_STATE_ACTIVE;
                 cws->peer_gone = 0;
diff --git a/src/transports/ws/sws.c b/src/transports/ws/sws.c
index dd49620..31099c9 100644
--- a/src/transports/ws/sws.c
+++ b/src/transports/ws/sws.c
@@ -165,7 +165,7 @@
 }
 
 void nn_sws_start (struct nn_sws *self, struct nn_usock *usock, int mode,
-    const char *resource, const char *host)
+    const char *host)
 {
     /*  Take ownership of the underlying socket. */
     nn_assert (self->usock == NULL && self->usock_owner.fsm == NULL);
@@ -174,7 +174,6 @@
     nn_usock_swap_owner (usock, &self->usock_owner);
     self->usock = usock;
     self->mode = mode;
-    self->resource = resource;
     self->remote_host = host;
 
     /*  Launch the state machine. */
@@ -235,7 +234,7 @@
             switch (type) {
             case NN_FSM_START:
                 nn_wshdr_start (&sws->wshdr, sws->usock,
-                    &sws->pipebase, sws->mode, sws->resource, sws->remote_host);
+                    &sws->pipebase, sws->mode, sws->remote_host);
                 sws->state = NN_SWS_STATE_HANDSHAKE;
                 return;
             default:
@@ -899,7 +898,6 @@
     nn_msg_mv (&sws->outmsg, msg);
 
     /*  Compose the message header. See RFC 6455, section 5.2. */
-    memset (sws->outhdr, 0, sizeof (sws->outhdr));
 
     /*  Messages are always sent in a single fragment.
         They may be split up on the way to the peer though. */
@@ -1020,8 +1018,8 @@
     
     case NN_SWS_INSTATE_RECVD_CHUNKED:
 
-        /*  This library should not deliver fragmented messages to the application,
-            so it's expected that this is the final frame. */
+        /*  This library should not deliver fragmented messages to the
+            application, so it's expected that this is the final frame. */
         nn_assert (sws->is_final_frame);
 
         len = sws->inmsg_total_size;
diff --git a/src/transports/ws/sws.h b/src/transports/ws/sws.h
index 532a756..3c32325 100644
--- a/src/transports/ws/sws.h
+++ b/src/transports/ws/sws.h
@@ -46,7 +46,7 @@
     first 2 bytes of initial framing + up to 8 bytes of additional
     extended payload length header + 4 byte mask = 14bytes
     Not all messages will use the maximum amount allocated, but we are
-    statically allocating this buffer for convenience. */
+    statically allocating this buffer as an optimisation. */
 #define NN_SWS_FRAME_MAX_HDR_LEN 14
 
 /*  Maximal payload size for messages with 7-bit size field. */
@@ -74,9 +74,6 @@
     /*  Pipe connecting this WebSocket connection to the nanomsg core. */
     struct nn_pipebase pipebase;
 
-    /*  Requested resource when acting as client. */
-    const char* resource;
-
     /*  Remote Host in header request when acting as client. */
     const char* remote_host;
 
@@ -136,7 +133,7 @@
 void nn_sws_term (struct nn_sws *self);
 int nn_sws_isidle (struct nn_sws *self);
 void nn_sws_start (struct nn_sws *self, struct nn_usock *usock, int mode,
-    const char *resource, const char *host);
+    const char *host);
 void nn_sws_stop (struct nn_sws *self);
 
 #endif
diff --git a/src/transports/ws/wshdr.c b/src/transports/ws/wshdr.c
index 59b859d..526ff45 100644
--- a/src/transports/ws/wshdr.c
+++ b/src/transports/ws/wshdr.c
@@ -145,12 +145,8 @@
 
 void nn_wshdr_start (struct nn_wshdr *self,
     struct nn_usock *usock, struct nn_pipebase *pipebase,
-    int mode, const char *resource, const char *host)
+    int mode, const char *host)
 {
-    /*  It's expected this resource has been allocated during intial connect. */
-    if (mode == NN_WS_CLIENT)
-        nn_assert (strlen (resource) >= 1);
-
     /*  Take ownership of the underlying socket. */
     nn_assert (self->usock == NULL && self->usock_owner.fsm == NULL);
     self->usock_owner.src = NN_WSHDR_SRC_USOCK;
@@ -159,7 +155,6 @@
     self->usock = usock;
     self->pipebase = pipebase;
     self->mode = mode;
-    self->resource = resource;
     self->remote_host = host;
 
     memset (self->opening_hs, 0, sizeof (self->opening_hs));
@@ -1026,14 +1021,13 @@
     iov.iov_base = self->opening_hs;
     iov.iov_len = snprintf (self->opening_hs,
         sizeof (self->opening_hs),
-        "GET %s HTTP/1.1\r\n"
+        "GET / HTTP/1.1\r\n"
         "Host: %s\r\n"
         "Upgrade: websocket\r\n"
         "Connection: Upgrade\r\n"
         "Sec-WebSocket-Key: %s\r\n"
         "Sec-WebSocket-Version: 13\r\n"
         "Sec-WebSocket-Protocol: SP-%d\r\n\r\n",
-        self->resource,
         self->remote_host,
         encoded_key,
         (int) self->pipebase->sock->socktype->protocol);
diff --git a/src/transports/ws/wshdr.h b/src/transports/ws/wshdr.h
index 9851514..5b802e1 100644
--- a/src/transports/ws/wshdr.h
+++ b/src/transports/ws/wshdr.h
@@ -75,9 +75,6 @@
     /*  Handle to the pipe. */
     struct nn_pipebase *pipebase;
 
-    /*  Requested resource when acting as client. */
-    const char* resource;
-
     /*  Remote Host in header request when acting as client. */
     const char* remote_host;
 
@@ -150,7 +147,7 @@
 int nn_wshdr_isidle (struct nn_wshdr *self);
 void nn_wshdr_start (struct nn_wshdr *self,
     struct nn_usock *usock, struct nn_pipebase *pipebase,
-    int mode, const char *resource, const char *host);
+    int mode, const char *host);
 void nn_wshdr_stop (struct nn_wshdr *self);
 
 #endif
diff --git a/tests/ws.c b/tests/ws.c
index 6d85f79..dc04507 100644
--- a/tests/ws.c
+++ b/tests/ws.c
@@ -36,8 +36,7 @@
     int rc;
     int sb;
     int sc;
-    //int opt;
-    //size_t sz;
+    int i;
 
     /*  Try closing bound but unconnected socket. */
     sb = test_socket (AF_SP, NN_PAIR);
@@ -53,19 +52,6 @@
     /*  Open the socket anew. */
     sc = test_socket (AF_SP, NN_PAIR);
 
-    /*  Check socket options. */
-    //sz = sizeof (opt);
-    //rc = nn_getsockopt (sc, NN_WS, NN_WS_HANDSHAKE_TIMEOUT, &opt, &sz);
-    //errno_assert (rc == 0);
-    //nn_assert (sz == sizeof (opt));
-    //nn_assert (opt == 1000);
-    //opt = 100;
-    //sz = sizeof (opt);
-    //rc = nn_getsockopt (sc, NN_WS, NN_WS_HANDSHAKE_TIMEOUT, &opt, &sz);
-    //errno_assert (rc == 0);
-    //nn_assert (sz == sizeof (opt));
-    //nn_assert (opt == 100);
-
     /*  Default port 80 should be assumed if not explicitly declared. */
     rc = nn_connect (sc, "ws://127.0.0.1");
     errno_assert (rc >= 0);
@@ -117,13 +103,31 @@
 
     test_close (sc);
 
-    /*  Test transferring one message. */
     sb = test_socket (AF_SP, NN_PAIR);
     test_bind (sb, "ws://127.0.0.1:5555");
     sc = test_socket (AF_SP, NN_PAIR);
     test_connect (sc, "ws://127.0.0.1:5555");
-    test_send (sc, "ABC");
-    test_recv (sb, "ABC");
+
+#if 0
+    /*  Ping-pong test. */
+    for (i = 0; i != 100; ++i) {
+#endif
+        test_send (sc, "ABC");
+        test_recv (sb, "ABC");
+#if 0
+        test_send (sb, "DEF");
+        test_recv (sc, "DEF");
+    }
+
+    /*  Batch transfer test. */
+    for (i = 0; i != 100; ++i) {
+        test_send (sc, "0123456789012345678901234567890123456789");
+    }
+    for (i = 0; i != 100; ++i) {
+        test_recv (sb, "0123456789012345678901234567890123456789");
+    }
+#endif
+
     test_close (sc);
     test_close (sb);