}
-int CtdlSockGetLine(int *sock, StrBuf *Target)
+int CtdlSockGetLine(int *sock, StrBuf * Target, int nSec)
{
CitContext *CCC=CC;
const char *Error;
rc = StrBufTCP_read_buffered_line_fast(Target,
CCC->sReadBuf,
&CCC->sPos,
- sock,
- 5,
- 1,
- &Error);
+ sock, nSec, 1, &Error);
if ((rc < 0) && (Error != NULL))
CtdlLogPrintf(CTDL_CRIT,
"%s failed: %s\n",
const char *pCh;
FlushStrBuf(CCC->sMigrateBuf);
- retval = CtdlSockGetLine(sock, CCC->sMigrateBuf);
+ retval = CtdlSockGetLine(sock, CCC->sMigrateBuf, 5);
i = StrLength(CCC->sMigrateBuf);
pCh = ChrPtr(CCC->sMigrateBuf);
return (-1);
}
bytes_written = bytes_written + retval;
+ if (IsNonBlock && (bytes_written == nbytes)){
+ tv.tv_sec = selectresolution;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&rfds);
+ FD_SET(*sock, &rfds);
+ if (select(*sock + 1, NULL, &rfds, NULL, &tv) == -1) {
+/// *Error = strerror(errno);
+ close (*sock);
+ *sock = -1;
+ return -1;
+ }
+ }
}
return (bytes_written);
}
* (This is implemented in terms of client_read() and could be
* justifiably moved out of sysdep.c)
*/
-int sock_getln_err(int *sock, char *buf, int bufsize, int *rc)
+int sock_getln_err(int *sock, char *buf, int bufsize, int *rc, int nSec)
{
int i, retval;
CitContext *CCC = MyContext();
const char *pCh;
FlushStrBuf(CCC->sMigrateBuf);
- *rc = retval = CtdlSockGetLine(sock, CCC->sMigrateBuf);
+ *rc = retval = CtdlSockGetLine(sock, CCC->sMigrateBuf, nSec);
i = StrLength(CCC->sMigrateBuf);
pCh = ChrPtr(CCC->sMigrateBuf);
* a multiline response, discarding the rest.
*/
-int ml_sock_gets(int *sock, char *buf)
+int ml_sock_gets(int *sock, char *buf, int nSec)
{
int rc = 0;
char bigbuf[1024];
int g;
- g = sock_getln_err(sock, buf, SIZ, &rc);
+ g = sock_getln_err(sock, buf, SIZ, &rc, nSec);
if (rc < 0)
return rc;
if (g < 4)
return (g);
do {
- g = sock_getln_err(sock, bigbuf, SIZ, &rc);
+ g = sock_getln_err(sock, bigbuf, SIZ, &rc, nSec);
if (rc < 0)
return rc;
if (g < 0)
int sock_read_to(int *sock, char *buf, int bytes, int timeout, int keep_reading_until_full);
int sock_read(int *sock, char *buf, int bytes, int keep_reading_until_full);
int sock_write(int *sock, const char *buf, int nbytes);
-int ml_sock_gets(int *sock, char *buf);
+int ml_sock_gets(int *sock, char *buf, int nSec);
int sock_getln(int *sock, char *buf, int bufsize);
-int CtdlSockGetLine(int *sock, StrBuf *Target);
+int CtdlSockGetLine(int *sock, StrBuf *Target, int nSec);
int sock_puts(int *sock, char *buf);
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
+#include <termios.h>
#include <fcntl.h>
#include <signal.h>
#include <pwd.h>
CCC->sPos = NULL;
/* Process the SMTP greeting from the server */
- if (ml_sock_gets(&sock, buf) < 0) {
+ if (ml_sock_gets(&sock, buf, 5) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP conversation");
goto bail;
snprintf(buf, sizeof buf, "EHLO %s\r\n", config.c_fqdn);
CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
sock_write(&sock, buf, strlen(buf));
- if (ml_sock_gets(&sock, buf) < 0) {
+ if (ml_sock_gets(&sock, buf, 5) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP HELO");
goto bail;
snprintf(buf, sizeof buf, "HELO %s\r\n", config.c_fqdn);
CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
sock_write(&sock, buf, strlen(buf));
- if (ml_sock_gets(&sock, buf) < 0) {
+ if (ml_sock_gets(&sock, buf, 5) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP HELO");
goto bail;
snprintf(buf, sizeof buf, "AUTH PLAIN %s\r\n", encoded);
CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
sock_write(&sock, buf, strlen(buf));
- if (ml_sock_gets(&sock, buf) < 0) {
+ if (ml_sock_gets(&sock, buf, 5) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP AUTH");
goto bail;
snprintf(buf, sizeof buf, "MAIL FROM:<%s>\r\n", envelope_from);
CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
sock_write(&sock, buf, strlen(buf));
- if (ml_sock_gets(&sock, buf) < 0) {
+ if (ml_sock_gets(&sock, buf, 5) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP MAIL");
goto bail;
snprintf(buf, sizeof buf, "RCPT TO:<%s@%s>\r\n", user, node);
CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
sock_write(&sock, buf, strlen(buf));
- if (ml_sock_gets(&sock, buf) < 0) {
+ if (ml_sock_gets(&sock, buf, 5) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP RCPT");
goto bail;
/* RCPT succeeded, now try the DATA command */
CtdlLogPrintf(CTDL_DEBUG, ">DATA\n");
sock_write(&sock, "DATA\r\n", 6);
- if (ml_sock_gets(&sock, buf) < 0) {
+ if (ml_sock_gets(&sock, buf, 5) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP DATA");
goto bail;
}
sock_write(&sock, ".\r\n", 3);
- if (ml_sock_gets(&sock, buf) < 0) {
+ tcdrain(sock);
+ if (ml_sock_gets(&sock, buf, 90) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP message transmit");
goto bail;
CtdlLogPrintf(CTDL_DEBUG, ">QUIT\n");
sock_write(&sock, "QUIT\r\n", 6);
- ml_sock_gets(&sock, buf);
+ ml_sock_gets(&sock, buf, 1);
CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
CtdlLogPrintf(CTDL_INFO, "SMTP client: delivery to <%s> @ <%s> (%s) succeeded\n",
user, node, name);