/* If the write would block (CURLE_AGAIN), we return CURLE_OK and (*written == 0). Otherwise we return regular CURLcode value.  */
CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, const void *mem, size_t len, ssize_t *written)
/* If the write would block (CURLE_AGAIN), we return CURLE_OK and (*written == 0). Otherwise we return regular CURLcode value.  */
CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, const void *mem, size_t len, ssize_t *written)
{
  ssize_t bytes_written;
  CURLcode result = CURLE_OK;
  int num = (sockfd == conn->sock[SECONDARYSOCKET]);
  bytes_written = conn->send[num](conn, num, mem, len, &result);
  *written = bytes_written;
  if(bytes_written >= 0)
    return CURLE_OK;
  switch(result) {
  case CURLE_AGAIN:
    *written = 0;
    return CURLE_OK;
  case CURLE_OK:
    return CURLE_SEND_ERROR;
  default:
    return result;
  }
}