Beispiel #1
0
void RedirectorSrv::server_sockevent( nlink_server *cptr, uint16 revents, void *myNet ) {
	NetworkInterface * client;
	struct nlink_client *ncptr;
	if(revents & PF_READ)
	{
		client = ( ( NetworkInterface * ) myNet )->getConnection( );
		if (!client) 
			return;
		uint32 nonblockingstate = true;
		IOCTL_SOCKET( client->getSocketID(), IOCTL_NOBLOCK, &nonblockingstate );

		ncptr = new nlink_client;
		if(ncptr == NULL)
			return;
		memset(ncptr, 0, sizeof(*ncptr));
		ncptr->hdr.type = RCLIENT;
		ncptr->hdr.fd = client->getSocketID();
		
		nlink_insert((struct nlink *)ncptr);

		Client *pClient = new Client();
		pClient->BindNI(client);
		ncptr->pClient = pClient;
		pClient->getNetwork()->sendData( mDestination.length( ), mDestination.c_str( ) );
		Log::getSingleton( ).outString( "REDIRECTOR: Sent world server" );
		disconnect_client( ncptr );
	}
}
Beispiel #2
0
/*
 *Set a device to BLOCKIO or NOBLOCKIO - may be used as a toggle
 */
int tc_blockio(TCDevice * device, TCCommBlocking blockflag)
{
    char client_str[TC_TAG_LENGTH + 256];
    int on = 1;
    int off = 0;

    if (device == NULL) {
        return TC_EWOULDBLOCK;
    }

    /* Status message */
    sprintf(client_str, "(ID = %d  tag = %s)", device->client_id, device->client_tag);
    trick_error_report(device->error_handler, TRICK_ERROR_TRIVIAL, __FILE__,
                       __LINE__, "%s blockflag = %d\n", client_str, blockflag);


    switch (blockflag) {

        case TC_COMM_BLOCKIO:
            /* Set socket to blocking */
            if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &off) < 0) {
                trick_error_report(device->error_handler,
                                   TRICK_ERROR_ALERT, __FILE__, __LINE__, "could not set socket to blocking\n");
                return (TC_EWOULDBLOCK);
            }
            device->blockio_type = blockflag;
            break;

        case TC_COMM_NOBLOCKIO:
            /* Set socket to non-blocking */
            if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &on) < 0) {
                trick_error_report(device->error_handler,
                                   TRICK_ERROR_ALERT, __FILE__, __LINE__, "could not set socket to non-blocking\n");
                return (TC_EWOULDBLOCK);
            }
            device->blockio_type = blockflag;
            break;

        case TC_COMM_TIMED_BLOCKIO:
            /* Set socket to non-blocking */
            if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &on) < 0) {
                trick_error_report(device->error_handler,
                                   TRICK_ERROR_ALERT, __FILE__,
                                   __LINE__, "could not set socket to software-blocking\n");
                return (TC_EWOULDBLOCK);
            }
            device->blockio_type = blockflag;
            break;

        case TC_COMM_ALL_OR_NOTHING:
            /* Set socket to non-blocking */
            if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &on) < 0) {
                trick_error_report(device->error_handler,
                                   TRICK_ERROR_ALERT, __FILE__, __LINE__, "could not set socket to all_or nothing\n");
                return (TC_EWOULDBLOCK);
            }
            device->blockio_type = blockflag;
            break;

        default:
            trick_error_report(device->error_handler,
                               TRICK_ERROR_ALERT, __FILE__, __LINE__,
                               "Invalid second argument."
                               "Second argument should be one of the following:\n"
                               "  TC_COMM_BLOCKIO,\n"
                               "  TC_COMM_NOBLOCKIO,\n" "  TC_COMM_TIMED_BLOCKIO,\n" "  TC_COMM_ALL_OR_NOTHING\n\n");
            return (TC_EWOULDBLOCK);
    }

    return (0);

}