- _notes_buffer.reset (new char[65536]);
- FILE* notes = fmemopen (_notes_buffer.get(), 65536, "w");
- curl_easy_setopt (curl, CURLOPT_STDERR, notes);
-
- curl_multi_add_handle (mcurl, curl);
-
- time_t start = time (0);
-
- int still_running = 1;
- curl_multi_perform (mcurl, &still_running);
-
- while (still_running) {
-
- fd_set fdread;
- fd_set fdwrite;
- fd_set fdexcep;
-
- FD_ZERO (&fdread);
- FD_ZERO (&fdwrite);
- FD_ZERO (&fdexcep);
-
- struct timeval timeout;
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
-
- long curl_timeout = -1;
- curl_multi_timeout (mcurl, &curl_timeout);
- if (curl_timeout >= 0) {
- timeout.tv_sec = curl_timeout / 1000;
- if (timeout.tv_sec > 1) {
- timeout.tv_sec = 1;
- } else {
- timeout.tv_usec = (curl_timeout % 1000) * 1000;
- }
- }
-
- int maxfd = -1;
- CURLMcode mc = curl_multi_fdset (mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
-
- if (mc != CURLM_OK) {
- fclose (notes);
- throw KDMError (String::compose ("Failed to send KDM email to %1", _to));
- }
-
- int rc;
- if (maxfd == -1) {
-#ifdef DCPOMATIC_WINDOWS
- Sleep (100);
- rc = 0;
-#else
- struct timeval wait = { 0, 100 * 1000};
- rc = select (0, 0, 0, 0, &wait);
-#endif
- } else {
- rc = select (maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
- }
-
- if (rc < 0) {
- throw KDMError ("Failed to send KDM email");
- }
-
- mc = curl_multi_perform (mcurl, &still_running);
- if (mc != CURLM_OK) {
- fclose (notes);
- throw KDMError (String::compose ("Failed to send KDM email (%1)", curl_multi_strerror (mc)));
- }
-
- if (job) {
- job->set_progress_unknown ();
- }
-
- if ((time(0) - start) > 10) {
- fclose (notes);
- throw KDMError (_("Failed to send KDM email (timed out)"));
- }