1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net: extract a common Socket struct, reuse it by embedding in TcpSocket & UdpSocket (#13559)

This commit is contained in:
gcxfd 2022-02-22 16:34:38 +08:00 committed by GitHub
parent 7bd8503170
commit ee1de06678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

11
vlib/net/socket.v Normal file
View File

@ -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)
}

View File

@ -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)
}

View File

@ -8,7 +8,7 @@ const (
)
struct UdpSocket {
handle int
Socket
l Addr
// TODO(emily): replace with option again
// when i figure out how to coerce it properly
@ -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 {