Search code examples
c++socketstcpnetwork-programmingboost-asio

Synchronous reading of multiple TCP responses


I'm writing a simple POP3 client. When I make for example LIST request to a POP3 server it responds with indexes and sizes (bytes) of available messages. It looks like this:

+OK 3 messages\r\n
1 103\r\n
2 140\r\n
3 184\r\n

I'm using boost::asio::read_until with \r\n as a delimiter, but this way I can't keep synchronization, because sometimes only the first part is being read, e.g. +OK 3 messages\r\n1 103\r\n and that's the optimistic case. I want my program to wait for the last part of a message. The only solution I came up with is to put sleep() after making a request and before reading it, but it doesn't seem to be reliable nor convenient solution. What are better ways for dealing with that?


Solution

  • According to POP3 specification the secret is to wait for a proper delimiter, which is .\r\n

    credits: @RemyLebeau