Basically, I'm trying to implement a universal multi-threaded TCP server that can handle arbitrary usage requests on two different servers with slightly different needs.
My requirements:
- The request cannot begin to be processed until the entire initial request has been received. (Essentially, I have a fixed size request header, which, among other things, includes the size of the entire request).
- Processing the request may result in several response messages to the requesting client. IE, as a rule, requests can be processed in one answer, but sometimes, in response to lengthy database transactions, I need to respond to the client, letting them know that I am still working and not wasting time on the connection.
To achieve this, I followed the example of HTTP server # 2 from boost v1.44 pretty closely. In general, the example worked for simple cases. I noticed that when I scale to address multiple requests at the same time, the changes I made somehow led to the fact that all requests were processed in turn by one thread. Obviously I'm doing something wrong.
I can’t publish all the actual code that I use due to the limitations of the employer, but suffice it to say that I saved asynchronous calls to accept new connections, but replaced asynchronous read / write with synchronous calls. If there are specific fragments that you think you need to see, I can see what I can do.
Essentially, I'm looking for how to specify how to use boost :: asio for a multi-threaded TCP server, where individual connections are handled by a single thread with synchronous I / O. Again, keep in mind that my abstraction is based on the example of http # 2 server (one io_service per processor), but I'm flexible for an alternative
source
share