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:
parent
7bd8503170
commit
ee1de06678
11
vlib/net/socket.v
Normal file
11
vlib/net/socket.v
Normal 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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user