mirror of https://github.com/v2ray/v2ray-core
api doc
parent
28fa84ce69
commit
a6d81cc56d
|
@ -35,6 +35,8 @@ func init() {
|
|||
|
||||
// GetPool returns a sync.Pool that generates bytes array with at least the given size.
|
||||
// It may return nil if no such pool exists.
|
||||
//
|
||||
// v2ray:api:stable
|
||||
func GetPool(size int32) *sync.Pool {
|
||||
for idx, ps := range poolSize {
|
||||
if size <= ps {
|
||||
|
@ -45,6 +47,8 @@ func GetPool(size int32) *sync.Pool {
|
|||
}
|
||||
|
||||
// Alloc returns a byte slice with at least the given size. Minimum size of returned slice is 2048.
|
||||
//
|
||||
// v2ray:api:stable
|
||||
func Alloc(size int32) []byte {
|
||||
pool := GetPool(size)
|
||||
if pool != nil {
|
||||
|
@ -54,6 +58,8 @@ func Alloc(size int32) []byte {
|
|||
}
|
||||
|
||||
// Free puts a byte slice into the internal pool.
|
||||
//
|
||||
// v2ray:api:stable
|
||||
func Free(b []byte) {
|
||||
size := int32(cap(b))
|
||||
b = b[0:cap(b)]
|
||||
|
|
|
@ -58,6 +58,8 @@ func (dl *DefaultListener) ListenPacket(ctx context.Context, addr net.Addr, sock
|
|||
|
||||
// RegisterListenerController adds a controller to the effective system listener.
|
||||
// The controller can be used to operate on file descriptors before they are put into use.
|
||||
//
|
||||
// v2ray:api:beta
|
||||
func RegisterListenerController(controller func(network, address string, fd uintptr) error) error {
|
||||
if controller == nil {
|
||||
return newError("nil listener controller")
|
||||
|
|
|
@ -52,10 +52,16 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, settings
|
|||
return listener, nil
|
||||
}
|
||||
|
||||
// ListenSystem listens on a local address for incoming TCP connections.
|
||||
//
|
||||
// v2ray:api:beta
|
||||
func ListenSystem(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.Listener, error) {
|
||||
return effectiveListener.Listen(ctx, addr, sockopt)
|
||||
}
|
||||
|
||||
// ListenSystemPacket listens on a local address for incoming UDP connections.
|
||||
//
|
||||
// v2ray:api:beta
|
||||
func ListenSystemPacket(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.PacketConn, error) {
|
||||
return effectiveListener.ListenPacket(ctx, addr, sockopt)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue