views:

25

answers:

1

I have problems implementing SMTP protocol over WinSock API. Here's what I do now. The client creates a non-blocking socket, connects to the server and exchanges data with it.

It uses "send string" primitive which efectively calls send() in a loop until the whole string is transmitted and "receive string" primitive which calls recv() in a loop until a string ending with CRLF is accumulated or timeout occurs.

The above dumb approach works, except on one specific server deployed at the customer's site. On this server the client sends EHLO, AUTH, MAIL FROM, RCPT, DATA, each time receiving a reasonable responce. Then it sends the mail message body line-by-line (not trying to receive anything from the server) and after some time send() (several hundred lines sent) stars returning WSAEWOULDBLOCK.

How do I handle this? Do I have to check for pending input on the socket after each line? Or what else should I do to predict and possibly prevent this situation?

A: 

From the documentation:

This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later.

Luke