/** * Helper routine to try and write up to one chunk of data from the buffer * to the socket. Return how much was written. * @param wait Wait * @return int */ static int flush_write_buffer(int wait) { fd_set fds; struct timeval tv = { 0, 0 }; int errno_save = ano_sockgeterr(); if (write_bufend == write_curpos || write_fd == -1) return 0; FD_ZERO(&fds); FD_SET(write_fd, &fds); if (select(write_fd + 1, 0, &fds, 0, wait ? NULL : &tv) == 1) { int maxwrite, nwritten; if (write_curpos > write_bufend) /* wrapped around? */ maxwrite = write_buftop - write_curpos; else if (write_bufend == write_netbuf) maxwrite = write_buftop - write_curpos - 1; else maxwrite = write_bufend - write_curpos; nwritten = ano_sockwrite(write_fd, write_curpos, maxwrite); errno_save = ano_sockgeterr(); if (debug >= 3) alog("debug: flush_write_buffer wanted %d, got %d", maxwrite, nwritten); if (nwritten > 0) { write_curpos += nwritten; if (write_curpos == write_buftop) write_curpos = write_netbuf; total_written += nwritten; return nwritten; } } ano_sockseterr(errno_save); return 0; }
/* Send a line of text */ int smtp_send(const char *text) { int result = ano_sockwrite(smail.sock, text, strlen(text)); alog("SMTP: sent %s",text); if (result == SOCKET_ERROR) ano_sockclose(smail.sock); return result; }