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:**
- HTTP task receives file upload
- File data is read into a handoff buffer
- File descriptor is passed to processing task via mailbox
- Processing task handles file display and socket closure
- 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:**
- Raw post callback intercepts HTTP request
- Request structure is copied for handoff
- Socket is passed to processing task via mailbox
- Processing task uses existing callback system
- 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
- Compile and Deploy: Build the application using the NNDK framework
- Network Setup: Application waits for DHCP address assignment
- Web Access: Navigate to the device's IP address on port 80
- File Upload: Use either form to upload files:
filepost_bufferedFD.html - for buffered FD method
filepost_bufferedReq.html - for buffered request method
- 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)