Skip to content

Commit

Permalink
missing host error
Browse files Browse the repository at this point in the history
  • Loading branch information
saviorand committed Dec 30, 2023
1 parent bf244dd commit 3c79e1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mojoweb/net.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ alias tooManyColonsError = Error("too many colons in address")


fn split_host_port(hostport: String) raises -> (String, String):
var host: String
var port: String
var host: String = ""
var port: String = ""
let colon_index = hostport.rfind(":")
var j: Int = 0
var k: Int = 0
Expand Down Expand Up @@ -171,4 +171,8 @@ fn split_host_port(hostport: String) raises -> (String, String):
raise Error("unexpected ']' in address")
port = hostport[colon_index + 1 :]

if port == "":
raise missingPortError
if host == "":
raise Error("missing host")
return host, port
6 changes: 6 additions & 0 deletions mojoweb/python/net.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ struct PythonTCPListener(CollectionElement):
fn __init__(inout self, pymodules: PythonObject, addr: TCPAddr) raises:
self.__pymodules = pymodules
self.__addr = addr
self.socket = None

@always_inline
fn accept(self) raises -> PythonConnection:
if self.socket == None:
raise Error("socket is None, cannot accept")
let conn_addr = self.socket.accept()
return PythonConnection(self.__pymodules, Tuple(conn_addr))

fn close(self) raises:
if self.socket == None:
raise Error("socket is None, cannot close")
_ = self.socket.close()

fn addr(self) -> TCPAddr:
Expand Down Expand Up @@ -75,6 +80,7 @@ struct PythonConnection:
let py_conn_addr = PythonObject(conn_addr)
self.conn = py_conn_addr[0]
self.raddr = py_conn_addr[1]
self.laddr = ""
self.pymodules = pymodules

fn read(self, inout buf: Bytes) raises -> Int:
Expand Down

0 comments on commit 3c79e1e

Please sign in to comment.