upd10
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import netio
|
import netio
|
||||||
|
import netio.protocol
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// This is only for examples_test.v
|
// This is only for examples_test.v
|
||||||
@@ -8,7 +9,8 @@ fn main() {
|
|||||||
listen_addr := netio.SocketAddr.new_ipv4([..]u8[127, 0, 0, 1], 1088)
|
listen_addr := netio.SocketAddr.new_ipv4([..]u8[127, 0, 0, 1], 1088)
|
||||||
|
|
||||||
// Create server socket.
|
// Create server socket.
|
||||||
socket := netio.Socket.new(netio.af_inet, netio.sock_stream, 0)!
|
socket := netio.Socket.new(netio.af_inet, netio.sock_stream,
|
||||||
|
protocol.protocol_by_name('tcp')!.number)!
|
||||||
|
|
||||||
// Close server socket on exit.
|
// Close server socket on exit.
|
||||||
defer {
|
defer {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ module protocol
|
|||||||
import os
|
import os
|
||||||
import sync
|
import sync
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
// Mutex for accessing to protocol entries via getprotoent(3).
|
// Mutex for accessing to protocol entries via getprotoent(3).
|
||||||
__global netio_proto_mutex &sync.Mutex
|
__global netio_proto_mutex &sync.Mutex
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ pub:
|
|||||||
number int // The protocol number.
|
number int // The protocol number.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_proto(ent C.protoent) ProtocolEntry {
|
fn make_proto(ent &C.protoent) ProtocolEntry {
|
||||||
mut aliases := []string{}
|
mut aliases := []string{}
|
||||||
if unsafe { ent.p_aliases[0] != nil } {
|
if unsafe { ent.p_aliases[0] != nil } {
|
||||||
mut ptr := *ent.p_aliases
|
mut ptr := *ent.p_aliases
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import netio.protocol
|
||||||
|
|
||||||
|
fn test_protocols() {
|
||||||
|
assert protocol.protocols().len > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_protocol_by_name() {
|
||||||
|
assert protocol.protocol_by_name('tcp')!.aliases == ['TCP']
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_protocol_by_number() {
|
||||||
|
tcp_proto := protocol.protocol_by_name('tcp')!
|
||||||
|
assert protocol.protocol_by_number(tcp_proto.number)!.name == 'tcp'
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user