Exemplo n.º 1
0
func (fd *udtFD) accept() (*udtFD, error) {
	if err := fd.incref(); err != nil {
		return nil, err
	}
	defer fd.decref()

	var sa syscall.RawSockaddrAny
	var salen C.int

	sock2 := C.udt_accept(fd.sock, (*C.struct_sockaddr)(unsafe.Pointer(&sa)), &salen)
	if sock2 == (C.UDTSOCKET)(C.INVALID_SOCK) {
		err := fd.lastErrorOp("accept")
		return nil, err
	}

	raddr, err := addrWithSockaddr(&sa)
	if err != nil {
		closeSocket(sock2)
		return nil, fmt.Errorf("error converting address: %s", err)
	}

	remotefd, err := newFD(sock2, fd.laddr, raddr, fd.net)
	if err != nil {
		closeSocket(sock2)
		return nil, err
	}

	if err = remotefd.setAsyncOpts(); err != nil {
		remotefd.Close()
		return nil, err
	}

	return remotefd, nil
}
Exemplo n.º 2
0
func Accept(socket *Socket) (newSocket *Socket, err error) {

	var rsa syscall.RawSockaddrAny
	var addrlen C.int

	newSock := C.udt_accept(socket.sock, (*C.struct_sockaddr)(unsafe.Pointer(&rsa)),
		&addrlen)

	if C.int(newSock) == C.int(C.UDT_INVALID_SOCK) {
		return nil, udtErrDesc("Unable to accept on socket")
	}

	newSocket = &Socket{
		sock: newSock,
	}

	return
}