@@ -133,7 +133,7 @@ send sock dat = do
133||| + `ResultCode` :: The result of the underlying function.
133||| + `ResultCode` :: The result of the underlying function.
135||| @sock The socket on which to receive the message.
135||| @sock The socket on which to receive the message.
136−||| @len How much of the data to send.
136+||| @len How much of the data to receive.
137recv : (sock : Socket)
137recv : (sock : Socket)
138 -> (len : ByteLength)
138 -> (len : ByteLength)
139 -> IO (Either SocketError (String, ResultCode))
139 -> IO (Either SocketError (String, ResultCode))
@@ -164,6 +164,25 @@ recv sock len = do
164 freeRecvStruct (RSPtr recv_struct_ptr)
164 freeRecvStruct (RSPtr recv_struct_ptr)
165 pure $ Right (payload, recv_res)
165 pure $ Right (payload, recv_res)
167+||| Receive all the remaining data on the specified socket.
169+||| Returns on failure a `SocketError`
170+||| Returns on success the payload `String`
172+||| @sock The socket on which to receive the message.
174+recvAll : (sock : Socket) -> IO (Either SocketError String)
175+recvAll sock = recvRec sock [] 64
178+ recvRec : Socket -> List String -> ByteLength -> IO (Either SocketError String)
179+ recvRec sock acc n = do res <- recv sock n
181+ Left 0 => pure (Right $ concat $ reverse acc)
182+ Left c => pure (Left c)
183+ Right (str, _) => let n' = min (n * 2) 65536 in
184+ recvRec sock (str :: acc) n'
167||| Send a message.
186||| Send a message.
169||| Returns on failure a `SocketError`
188||| Returns on failure a `SocketError`