Ejemplo n.º 1
0
JNIEXPORT void JNICALL Java_com_aio4c_Connection_close(JNIEnv* jvm, jobject connection, jboolean force) {
    void* myConnection = NULL;

    GetPointer(jvm, connection, &myConnection);

    ConnectionClose(myConnection, force);
}
Ejemplo n.º 2
0
UINT WINAPI ProcessConnection(LPVOID arg) {
	SOCKET connectSocket = (SOCKET) arg;
	HttpConnection connection;

	ConnectionInit(&connection, connectSocket);
	while (TRUE) {
		if (!ContextInit(&connection.ctx,  &connection) )
			break;
#ifdef _DEBUG	
		showContext(&connection.ctx);
#endif
	 
		ProcessRequest(&connection.ctx);
			
		if (strcmp("Keep-Alive", HeaderGet(&connection.ctx.reqList, "Connection"))) {
			break;
		}
#ifdef _DEBUG
		printf("Processing done!\n");
#endif
	}
	
    ConnectionClose(&connection);
#ifdef _DEBUG
	_tprintf(_T("release connection!\n"));
#endif	
	return 0;
}
Ejemplo n.º 3
0
/**
  * @brief Slot to emit signals used by the mainwindow to start the telemetry thread
  * @param Pointer to button from the dialogue box
  */
void wifiComms::buttonBoxChanged(QAbstractButton* btnAbstract)
{
    // Take strings and numbers from the dialogue boxes
    quint16 serverPort = ui->serverPortlineEdit->text().toUInt();
    QString serverIP = ui->serverIPlineEdit->text();
    quint16 clientPort = ui->clientPortlineEdit->text().toUInt();
    QString clientIP = ui->clientIPlineEdit->text();

    AHNS_DEBUG("wifiComms::buttonBoxChanged()");

    if ((btnAbstract->text() == "Close") || (btnAbstract->text() == "&Close"))
    {
        AHNS_DEBUG("wifiComms::buttonBoxChanged() [ Close ]");

        emit ConnectionClose();
    }
    else if (btnAbstract->text() == "Open")
    {
        AHNS_DEBUG("wifiComms::buttonBoxChanged() [ Open ]");

        emit ConnectionStart(serverPort, serverIP, clientPort, clientIP);
    }
    else if (btnAbstract->text() == "Retry")
    {
        AHNS_DEBUG("wifiComms::buttonBoxChanged() [ Retry ]");

        emit ConnectionRetry(serverPort, serverIP, clientPort, clientIP);
    }
    else if (btnAbstract->text() == "Restore Defaults")
    {
        AHNS_DEBUG("wifiComms::buttonBoxChanged() [ Restore Defaults ]");

        ui->serverIPlineEdit->setText(DEFAULT_SERVER_IP);
        ui->serverPortlineEdit->setText(DEFAULT_SERVER_PORT);
        ui->clientIPlineEdit->setText(DEFAULT_CLIENT_IP);
        ui->clientPortlineEdit->setText(DEFAULT_CLIENT_PORT);
    }
    else // ui is wrong
    {
        AHNS_DEBUG("wifiComms::buttonBoxChanged() [ UNDEFINED BUTTON ]");
    }
}
Ejemplo n.º 4
0
static Connection* __ConnectionHandleError(char* file, int line, Connection* connection, LogLevel level, Error error, ErrorCode* code) {
    connection->closedForError = true;

    switch (error) {
        case AIO4C_BUFFER_OVERFLOW_ERROR:
        case AIO4C_BUFFER_UNDERFLOW_ERROR:
            _Raise(file, line, level, AIO4C_BUFFER_ERROR_TYPE, error, code);
            break;
        case AIO4C_CONNECTION_STATE_ERROR:
            code->connection = connection;
            _Raise(file, line, level, AIO4C_CONNECTION_STATE_ERROR_TYPE, error, code);
            break;
        case AIO4C_CONNECTION_DISCONNECTED:
            connection->closedForError = false;
        default:
            code->connection = connection;
            _Raise(file, line, level, AIO4C_CONNECTION_ERROR_TYPE, error, code);
            break;
    }

    return ConnectionClose(connection, true);
}
Ejemplo n.º 5
0
int main (int argc, const char * argv[])
    // The primary entry point.
{
    int             err;
    ConnectionRef   conn;
    
    conn = NULL;
    
    // If we get no arguments, just print the usage and fail.
    
    err = 0;
    if (argc == 1) {
        PrintUsage(argv[0]);
        err = ECANCELED;
    }
    
    // SIGPIPE is evil, so tell the system not to send it to us.
    
    if (err == 0) {
        err = MoreUNIXIgnoreSIGPIPE();
    }

    // Organise to have SIGINT delivered to a runloop callback.
    
    if (err == 0) {
        sigset_t    justSIGINT;
        
        (void) sigemptyset(&justSIGINT);
        (void) sigaddset(&justSIGINT, SIGINT);
        
        err = InstallSignalToSocket(
            &justSIGINT,
            CFRunLoopGetCurrent(),
            kCFRunLoopDefaultMode,
            SIGINTRunLoopCallback,
            NULL
        );
    }
    
    // Connect to the server.
    
    if (err == 0) {
        err = ConnectionOpen(&conn);
    }
    
    // Process the command line arguments.  Basically the arguments are a 
    // sequence of commands, which we process in order.  The logic is 
    // a little convoluted because some commands have arguments and because 
    // the "listen" command must come last.
    
    if (err == 0) {
        Boolean printTheUsage;
        int     argIndex;
        
		printTheUsage = false;
		
        argIndex = 1;
        while ( (err == 0) && (argIndex < argc) ) {
            if ( strcmp(argv[argIndex], "nop") == 0 ) {
                DoNOP(conn);
            } else if ( strcmp(argv[argIndex], "whisper") == 0 ) {
                argIndex += 1;
                if (argIndex < argc) {
                    DoWhisper(conn, argv[argIndex]);
                } else {
                    printTheUsage = true;
                    err = ECANCELED;
                }
            } else if ( strcmp(argv[argIndex], "shout") == 0 ) {
                argIndex += 1;
                if (argIndex < argc) {
                    DoShout(conn, argv[argIndex]);
                } else {
                    printTheUsage = true;
                    err = ECANCELED;
                }
            } else if ( strcmp(argv[argIndex], "listen") == 0 ) {
                if ( (argIndex + 1) == argc ) {         // if listen is the last argument
                    DoListen(conn);
                } else {
                    printTheUsage = true;
                    err = ECANCELED;
                }
            } else if ( strcmp(argv[argIndex], "quit") == 0 ) {
                DoQuit(conn);
            } else {
                printTheUsage = true;
                err = ECANCELED;
            }
            argIndex += 1;
        }
        
        if (printTheUsage) {
            PrintUsage(argv[0]);
        }
    }
    
    // Clean up.
    
    ConnectionClose(conn);

    if ( (err != 0) && (err != ECANCELED) ) {
        fprintf(stderr, "SimpleClientCF: Failed with error %d.\n", err);
    }
    
    return (err == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}