diff --git a/vlib/net/socket.v b/vlib/net/socket.v new file mode 100644 index 0000000000..0ea920d38b --- /dev/null +++ b/vlib/net/socket.v @@ -0,0 +1,11 @@ +module net + +pub struct Socket { + pub: + handle int +} + +// address gets the address of a socket +pub fn (s &Socket) address() ?Addr { + return addr_from_socket_handle(s.handle) +} diff --git a/vlib/net/tcp.v b/vlib/net/tcp.v index 92305a1449..428629398d 100644 --- a/vlib/net/tcp.v +++ b/vlib/net/tcp.v @@ -296,8 +296,7 @@ pub fn (c &TcpListener) addr() ?Addr { } struct TcpSocket { -pub: - handle int + Socket } fn new_tcp_socket(family AddrFamily) ?TcpSocket { @@ -418,8 +417,3 @@ fn (mut s TcpSocket) connect(a Addr) ? { // otherwise we timed out return err_connect_timed_out } - -// address gets the address of a socket -pub fn (s &TcpSocket) address() ?Addr { - return addr_from_socket_handle(s.handle) -} diff --git a/vlib/net/udp.v b/vlib/net/udp.v index ad4bf3f632..5c10444354 100644 --- a/vlib/net/udp.v +++ b/vlib/net/udp.v @@ -8,8 +8,8 @@ const ( ) struct UdpSocket { - handle int - l Addr + Socket + l Addr // TODO(emily): replace with option again // when i figure out how to coerce it properly mut: @@ -259,11 +259,6 @@ fn new_udp_socket_for_remote(raddr Addr) ?&UdpSocket { return sock } -// address gets the address of a socket -pub fn (s &UdpSocket) address() ?Addr { - return addr_from_socket_handle(s.handle) -} - pub fn (mut s UdpSocket) set_option_bool(opt SocketOption, value bool) ? { // TODO reenable when this `in` operation works again // if opt !in opts_can_set {