NetBurner 3.5.7
PDF Version
HTML File Post Task Handoff

File Post Task Handoff Example

Overview

This application demonstrates two different methods for handling file uploads in a web server environment without blocking the main HTTP task. The example provides a web interface for file uploads and processes them using task handoff techniques to maintain server responsiveness during potentially time-consuming file operations.

Application Architecture

The application consists of several key components:

  • Main HTTP Server: Handles incoming web requests
  • File Upload Handlers: Two different approaches for processing uploaded files
  • Task Handoff System: Prevents blocking of the main HTTP thread during file processing

File Upload Methods

Method 1: Buffered File Descriptor Handoff (filepost_bufferedFD.cpp)

This method uses a file descriptor buffer to hand off file processing to a separate task.

Key Features:**

  • Uses FDcBuf adapter for buffered file descriptor operations
  • Implements mailbox communication between HTTP and processing tasks
  • Supports both binary and text file display
  • Buffer size limited to 10,000 bytes
  • Selective handoff based on filename (userfile1 is processed synchronously)

    Flow:**

  1. HTTP task receives file upload
  2. File data is read into a handoff buffer
  3. File descriptor is passed to processing task via mailbox
  4. Processing task handles file display and socket closure
  5. Semaphore coordinates task availability

Method 2: Buffered Request Handoff (filepost_bufferedReq.cpp)

This method hands off the entire HTTP request to a separate processing task.

Key Features:**

  • Copies the complete HTTP request structure
  • Uses raw post callback handler
  • Processes files in dedicated task context
  • Direct request forwarding to existing callback system
  • Buffer size limited to 10,000 bytes

    Flow:**

  1. Raw post callback intercepts HTTP request
  2. Request structure is copied for handoff
  3. Socket is passed to processing task via mailbox
  4. Processing task uses existing callback system
  5. Semaphore ensures single request processing

Technical Components

Synchronization Primitives

  • OS_MBOX: Mailbox for passing socket handles between tasks
  • OS_SEM: Semaphores for coordinating task availability
  • Timeouts: HTTP_TIMEOUT used for non-blocking operations

Buffer Management

  • FILE_BUFFER_SIZE: 10,000 byte limit for file processing
  • FileRxBuffer: Main buffer for synchronous processing
  • HandoffFileRxBuffer: Separate buffer for handoff operations

Web Interface

  • HTML Forms: Two different forms for testing each handoff method
  • File Display: Support for both text and binary file visualization
  • Checkbox Control: Option to display binary files

File Processing Features

File Reading

  • Reads uploaded files in chunks up to buffer limit
  • Handles both text and binary file types
  • Graceful handling of files exceeding buffer size

Display Options

  • Text Mode: Displays file content as readable text
  • Binary Mode: Shows binary file content (controlled via checkbox)
  • HTML Formatting: Uses <PRE> tags for proper text formatting

Error Handling

  • Timeout protection for task handoffs
  • Graceful degradation when handoff is unavailable
  • Error messages for failed file extractions

Usage

  1. Compile and Deploy: Build the application using the NNDK framework
  2. Network Setup: Application waits for DHCP address assignment
  3. Web Access: Navigate to the device's IP address on port 80
  4. File Upload: Use either form to upload files:
    • filepost_bufferedFD.html - for buffered FD method
    • filepost_bufferedReq.html - for buffered request method
  5. Options: Check binary display option if needed

Configuration

Task Priorities

  • HttpHandoffTask_BufferedFd: MAIN_PRIO+1
  • HttpHandoffTask_BufferedReq: MAIN_PRIO+2

Timeouts

  • Network Wait: 5 seconds for active network
  • Handoff Timeout: HTTP_TIMEOUT/4 for task availability

Buffer Limits

  • Maximum File Size: 10,000 bytes per upload
  • Read Chunk Size: 80 bytes for display operations

Benefits

Performance

  • Non-blocking HTTP server operation
  • Concurrent file processing capability
  • Responsive web interface during uploads

Flexibility

  • Two different handoff approaches for various use cases
  • Configurable binary/text display modes
  • Selective processing based on file identification

File Structure

/
main.cpp # Application entry point
filepost_bufferedFD.cpp # Buffered FD handoff method
filepost_bufferedReq.cpp # Buffered request handoff method
filepost_bufferedFD.html # Web form for FD method (referenced)
filepost_bufferedReq.html # Web form for request method (referenced)