Sign in

    socket

    A socket binding for MoonBit

    socket
    Download zip
    Author
    Version
    0.1.2-rc2
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    1K

    #A socket binding for MoonBit

    #Usage

    To use a package from this repository, add module fangyinc/socket to dependencies by command

    moon add fangyinc/socket

    And import socket in your moon.pkg.json file. for example:

    { "import": [ "fangyinc/socket/lib" ] }

    #Use Example

    You can find the tcp echo server example in src/examples/tcp_server and the tcp client example in src/examples/tcp_client.

    RawPointer

    trait RawPointer

    ToAIFlags

    pub(open) trait ToAIFlags {
    to_ai_flags(self : Self) -> AIFlags raise NetError
    }

    ToCString

    pub(open) trait ToCString {
    to_cstring(self : Self) -> Bytes
    }

    impl ToCString for String

    ToDomain

    pub(open) trait ToDomain {
    to_domain(self : Self) -> Domain raise NetError
    }

    impl ToDomain for Unit

    ToIpaddr

    pub(open) trait ToIpaddr {
    ip_name(self : Self) -> String raise NetError
    to_socket_addr(self : Self) -> SocketAddr raise NetError
    to_ipaddr(self : Self) -> Ipaddr raise NetError
    }

    ToProtocol

    pub(open) trait ToProtocol {
    to_protocol(self : Self) -> Protocol raise NetError
    }

    ToShutdown

    pub(open) trait ToShutdown {
    to_shutdown(self : Self) -> Shutdown raise NetError
    }

    ToSocketAddrs

    pub(open) trait ToSocketAddrs {
    to_socket_addr(self : Self) -> Iter[SocketAddr] raise NetError
    }

    ToType

    pub(open) trait ToType {
    to_type(self : Self) -> Type raise NetError
    }

    AIFlags

    pub(all) enum AIFlags {
    AI_PASSIVE
    AI_CANONNAME
    AI_ALL
    AI_NUMERICHOST
    AI_NUMERICSERV
    AI_ADDRCONFIG
    AI_V4MAPPED
    }

    impl Show for AIFlags

    AddrInfo

    pub struct AddrInfo {
    family : Int
    socktype : Int
    protocol : Int
    addr : Ipaddr
    canonname : String?
    }

    AddrInfoResults

    type AddrInfoResults

    AddrInfoResults::iter

    Domain

    pub(all) enum Domain {
    IPv4
    IPv6
    Unix
    }

    impl ToDomain for Domain
    impl Show for Domain

    Domain::from_address

    fn Domain::from_address(addr : SocketAddr) -> Domain

    Domain::inner

    fn Domain::inner(self : Domain) -> Int

    Ipaddr

    type Ipaddr

    impl ToIpaddr for Ipaddr

    Ipv4addr

    type Ipv4addr

    Ipv6addr

    type Ipv6addr

    NetError

    pub(all) type! NetError String

    impl Show for NetError

    Protocol

    pub(all) enum Protocol {
    TCP
    UDP
    ICMPV4
    ICMPV6
    }

    impl Show for Protocol

    Protocol::inner

    fn Protocol::inner(self : Protocol) -> Int

    Shutdown

    pub(all) enum Shutdown {
    Read
    Write
    Both
    }

    impl Show for Shutdown

    Shutdown::inner

    fn Shutdown::inner(self : Shutdown) -> Int

    Socket

    pub(all) struct Socket {
    inner : Int64
    }

    impl Show for Socket

    Socket::accept

    fn Socket::accept(self : Socket) -> (Socket, SocketAddr) raise NetError

    Socket::bind

    fn[S : ToSocketAddrs] Socket::bind(self : Socket, addr : S) -> Unit raise NetError

    Socket::close

    fn Socket::close(self : Socket) -> Unit raise NetError

    Socket::connect

    fn[S : ToSocketAddrs] Socket::connect(self : Socket, addr : S) -> Unit raise NetError

    Socket::listen

    fn Socket::listen(self : Socket, backlog~ : Int = ..) -> Unit raise NetError

    Socket::recv

    fn Socket::recv(self : Socket, buffer : FixedArray[Byte], flags~ : Int = ..) -> Int raise NetError

    Socket::send

    fn Socket::send(self : Socket, data : FixedArray[Byte], len : Int, flags~ : Int = ..) -> Int raise NetError

    Socket::set_broadcast

    fn Socket::set_broadcast(self : Socket, enable : Bool) -> Unit raise NetError

    Socket::set_keepalive

    fn Socket::set_keepalive(self : Socket, enable : Bool) -> Unit raise NetError

    Socket::set_recv_buffer_size

    fn Socket::set_recv_buffer_size(self : Socket, size : Int) -> Unit raise NetError

    Socket::set_send_buffer_size

    fn Socket::set_send_buffer_size(self : Socket, size : Int) -> Unit raise NetError

    Socket::setsockopt

    fn Socket::setsockopt(self : Socket, level : Int, optname : Int, optval : Int) -> Unit raise NetError

    Socket::shutdown

    fn Socket::shutdown(self : Socket, how : Shutdown) -> Unit raise NetError

    SocketAddr

    pub(all) enum SocketAddr {
    V4(String, UInt16)
    V6(String, UInt16, UInt, UInt)
    }

    impl Show for SocketAddr

    Type

    pub(all) enum Type {
    Stream
    Datagram
    Raw
    }

    impl ToType for Type
    impl Show for Type

    Type::inner

    fn Type::inner(self : Type) -> Int

    getaddrinfo

    fn[H : ToCString, S : ToCString, TDO : ToDomain, ToT : ToType, ToP : ToProtocol] getaddrinfo(hostname : H, service : S, ai_flags : Int, ai_family : TDO, ai_socktype : ToT, ai_protocol : ToP) -> AddrInfoResults raise NetError

    mbt_string_to_utf8_bytes

    fn mbt_string_to_utf8_bytes(str : String, is_filename : Bool) -> Bytes

    new

    fn new(domain : Domain, ty : Type, protocol~ : Protocol? = ..) -> Socket raise NetError

    utf8_bytes_to_mbt_string

    fn utf8_bytes_to_mbt_string(bytes : Bytes) -> String raise Error

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io