- sendto(sock->sock, data, data_len, 0, &remote.sa, SIZEOF_SOCKADDR(remote));
+ ret = sendto(sock->sock, data, data_len, 0, &remote.sa,
+ SIZEOF_SOCKADDR(remote));
+ if (ret < 0) {
+ if (errno == EAGAIN || errno == EINTR) {
+ SILC_LOG_DEBUG(("Could not send immediately, will do it later"));
+ silc_schedule_set_listen_fd(sock->schedule, sock->sock,
+ SILC_TASK_READ | SILC_TASK_WRITE, FALSE);
+ return -1;
+ }
+ SILC_LOG_DEBUG(("Cannot send to UDP socket: %s", strerror(errno)));
+ silc_schedule_unset_listen_fd(sock->schedule, sock->sock);
+ sock->sock_error = errno;
+ return -2;
+ }
+
+ SILC_LOG_DEBUG(("Sent data %d bytes", ret));
+ if (silc_schedule_get_fd_events(sock->schedule, sock->sock) &
+ SILC_TASK_WRITE)
+ silc_schedule_set_listen_fd(sock->schedule, sock->sock,
+ SILC_TASK_READ, FALSE);
+
+ return ret;