public void UDP_SocketOpenClose() { SL.C.Context ctx = default; Assert.True(API.Setup(&ctx)); C.Socket sock = C.Socket.NewUDP(&ctx, C.Endpoint.NewV4(&ctx, _port)); try { Assert.True(API.SocketOpen(&sock)); Assert.AreEqual(C.SocketState.Bound, sock.state); Assert.AreEqual(C.SocketFlags.None, sock.flags); Assert.AreEqual(0, sock.error); Assert.False(C.Socket.HasFlag(&sock, C.SocketFlags.NonBlocking)); Assert.True(API.SocketClose(&sock)); Assert.AreEqual(C.SocketState.Closed, sock.state); Assert.AreEqual(0, sock.fd); Assert.True(API.Cleanup(&ctx)); Assert.AreEqual(C.ContextState.Stopped, ctx.state); } finally { API.Cleanup(&ctx); } }
public void C_Socket_NewUDP() { Assert.True(IPAddress.TryParse("127.0.0.1", out IPAddress netip)); SL.C.Context ctx = default; Assert.True(API.Setup(&ctx)); try { C.Socket sock = C.Socket.NewUDP(&ctx, C.Endpoint.NewV4(&ctx, _port, C.IPv4.New(127, 0, 0, 1))); Assert.AreEqual(0, sock.fd); Assert.AreEqual(0, sock.dir); Assert.AreEqual(C.SocketState.New, sock.state); Assert.AreEqual(C.SockType.Dgram, (C.SockType)sock.type); Assert.AreEqual(C.SockProto.UDP, (C.SockProto)sock.proto); Assert.AreEqual(0, sock.error); Assert.AreEqual(C.SocketFlags.None, sock.flags); Assert.AreEqual(ctx.af_inet, sock.endpoint.af); Assert.AreEqual(_port, sock.endpoint.port); fixed(byte *pnetip = netip.GetAddressBytes()) Assert.True(Util.MemCmp((byte *)&sock.endpoint.addr4, 0, pnetip, 0, sizeof(C.IPv4))); Assert.True(API.Cleanup(&ctx)); } finally { API.Cleanup(&ctx); } }
public void UDP_SocketSetBlocking() { SL.C.Context ctx = default; Assert.True(API.Setup(&ctx)); C.Socket sock = C.Socket.NewUDP(&ctx, C.Endpoint.NewV4(&ctx, _port)); try { Assert.True(API.SocketOpen(&sock)); Assert.True(API.SocketNonBlocking(&sock, true)); Assert.True(C.Socket.HasFlag(&sock, C.SocketFlags.NonBlocking)); Assert.True(API.SocketClose(&sock)); Assert.True(API.Cleanup(&ctx)); } finally { API.SocketClose(&sock); API.Cleanup(&ctx); } }