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:
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 {
|
struct TcpSocket {
|
||||||
pub:
|
Socket
|
||||||
handle int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_tcp_socket(family AddrFamily) ?TcpSocket {
|
fn new_tcp_socket(family AddrFamily) ?TcpSocket {
|
||||||
@ -418,8 +417,3 @@ fn (mut s TcpSocket) connect(a Addr) ? {
|
|||||||
// otherwise we timed out
|
// otherwise we timed out
|
||||||
return err_connect_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,7 +8,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
struct UdpSocket {
|
struct UdpSocket {
|
||||||
handle int
|
Socket
|
||||||
l Addr
|
l Addr
|
||||||
// TODO(emily): replace with option again
|
// TODO(emily): replace with option again
|
||||||
// when i figure out how to coerce it properly
|
// when i figure out how to coerce it properly
|
||||||
@ -259,11 +259,6 @@ fn new_udp_socket_for_remote(raddr Addr) ?&UdpSocket {
|
|||||||
return sock
|
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) ? {
|
pub fn (mut s UdpSocket) set_option_bool(opt SocketOption, value bool) ? {
|
||||||
// TODO reenable when this `in` operation works again
|
// TODO reenable when this `in` operation works again
|
||||||
// if opt !in opts_can_set {
|
// if opt !in opts_can_set {
|
||||||
|
Reference in New Issue
Block a user