Exemplo n.º 1
0
void MultipartHandle::contentReceived(const char* data, size_t length)
{
    if (m_state == End)
        return; // The handler is closed down so ignore everything.

    m_buffer.append(data, length);

    while (processContent()) { }
}
Exemplo n.º 2
0
void MultipartHandle::contentEnded()
{
    // Process the leftover data.
    while (processContent()) { }

    if (m_state != End) {
        // It seems we are still not at the end of the processing.
        // Push out the remaining data.
        didReceiveData(m_buffer.size());
        m_state = End;
    }

    m_buffer.clear();
}
Exemplo n.º 3
0
int main(int argc, char** argv) {
    char* fcpath = argv[1];
    char* tcpath = argv[2];
    int fdfc;
    int fdtc;
    FILE* fd;
    char* buf;
    int len;
    struct reqmsg req;

    fdfc = open(fcpath, O_RDONLY);
    if(fdfc < 0) {
        error("WORKER - Open from client fifo");
    }

    fdtc = open(tcpath, O_WRONLY);
    if(fdtc < 0) {
        error("WORKER - Open to client fifo");
    }

    read(fdfc, &req, sizeof(struct reqmsg));

    fd = fopen(req.path, "rt");
    if(fd == NULL) {
        error("WORKER - Open content file");
    }

    buf = (char*)malloc(1024);

    while(fgets(buf, 1024, fd)) {
        buf = processContent(buf); 
        len = strlen(buf)+1;
        write(fdtc, &len, sizeof(int));
        write(fdtc, buf, len);
    }
    len = 0;
    write(fdtc, &len, sizeof(int));
 
    free(buf);
    fclose(fd);
    close(fdfc);
    close(fdtc);

    return 0;
}
Exemplo n.º 4
0
/*
 *  Process incoming requests. This will process as many requests as possible before returning. All socket I/O is 
 *  non-blocking, and this routine must not block. 
 */
void maProcessReadEvent(MaConn *conn, MaPacket *packet)
{
    mprAssert(conn);

    conn->canProceed = 1;
    mprLog(conn, 7, "ENTER maProcessReadEvent state %d, packet %p", conn->state, packet);
    
    while (conn->canProceed) {
        mprLog(conn, 7, "maProcessReadEvent, state %d, packet %p", conn->state, packet);

        switch (conn->state) {
        case MPR_HTTP_STATE_BEGIN:
            conn->canProceed = parseRequest(conn, packet);
            break;

        case MPR_HTTP_STATE_CONTENT:
            conn->canProceed = processContent(conn, packet);
            packet = conn->input;
            break;

        case MPR_HTTP_STATE_PROCESSING:
            conn->canProceed = maServiceQueues(conn);
            break;

        case MPR_HTTP_STATE_COMPLETE:
            conn->canProceed = maProcessCompletion(conn);
            packet = conn->input;
            break;

        default:
            conn->keepAliveCount = 0;
            mprAssert(0);
            return;
        }
    }
    mprLog(conn, 7, "LEAVE maProcessReadEvent state %d, packet %p, dedicated %d", conn->state, packet, conn->dedicated);
}