PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL PMC * Parrot_io_accept_win32(PARROT_INTERP, ARGMOD(PMC *socket)) { ASSERT_ARGS(Parrot_io_accept_win32) const Parrot_Socket_attributes * const io = PARROT_SOCKET(socket); PMC * newio = Parrot_io_new_socket_pmc(interp, PIO_F_SOCKET | PIO_F_READ|PIO_F_WRITE); Parrot_Socklen_t addrlen = sizeof (struct sockaddr_in); struct sockaddr_in *saddr; int newsock; PARROT_SOCKET(newio)->local = PARROT_SOCKET(socket)->local; PARROT_SOCKET(newio)->remote = Parrot_pmc_new(interp, enum_class_Sockaddr); saddr = SOCKADDR_REMOTE(newio); newsock = accept((int)io->os_handle, (struct sockaddr *)saddr, &addrlen); if (newsock == -1) { return PMCNULL; } PARROT_SOCKET(newio)->os_handle = (void*)newsock; /* XXX FIXME: Need to do a getsockname and getpeername here to * fill in the sockaddr_in structs for local and peer */ /* Optionally do a gethostyaddr() to resolve remote IP address. * This should be based on an option set in the master socket */ return newio; }
PARROT_EXPORT PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL INTVAL Parrot_io_socket_handle(PARROT_INTERP, ARGMOD_NULLOK(PMC *socket), INTVAL fam, INTVAL type, INTVAL proto) { ASSERT_ARGS(Parrot_io_socket_handle) PMC *new_socket; PIOHANDLE os_handle; if (PMC_IS_NULL(socket)) new_socket = Parrot_io_new_socket_pmc(interp, PIO_F_SOCKET|PIO_F_READ|PIO_F_WRITE); else new_socket = socket; os_handle = Parrot_io_socket(interp, fam, type, proto); SETATTR_Socket_os_handle(interp, new_socket, os_handle); SETATTR_Socket_family(interp, new_socket, fam); SETATTR_Socket_type(interp, new_socket, type); SETATTR_Socket_protocol(interp, new_socket, proto); return 0; }