D
dgiagio
Hi,
I'm creating a SMTP application and I would like to hear opinions about
error handling. Currently there are two functions that communicate with
the remote peer:
ssize_t smtp_puts(smtp_stream_t *stream, const char *fmt, ...);
ssize_t smtp_gets(smtp_stream_t *stream, char *buf, size_t len);
Both of them return the number of written bytes to the stream, or -1 if
an error ocurred. The error is set on errno, since they use write() and
read().
My approach is like the following:
if (smtp_puts(s, "HELO hostname") == -1) {
syslog(LOG_ERR, "smtp_puts: sending HELO: %m");
goto cleanup;
}
if (smtp_gets(s, buf, sizeof(buf) == -1) {
syslog(LOG_ERR," smtp_gets: receiving HELO: %m");
goto cleanup;
}
/* Process the HELO response */
if (smtp_check_helo(buf) == -1) {
syslog(LOG_ERR, "smtp_check_helo: bad HELO");
goto cleanup;
}
if (smtp_puts(s, "MAIL FROM:<postmaster>") == -1) {
syslog(LOG_ERR, "smtp_puts: sending MAIL FROM: %m");
goto cleanup;
}
if (smtp_gets(s, buf, sizeof(buf) == -1) {
syslog(LOG_ERR," smtp_gets: receiving MAIL FROM: %m");
goto cleanup;
}
/* Process the MAIL FROM response */
if (smtp_check_mailfrom(buf) == -1) {
syslog(LOG_ERR, "smtp_check_mailfrom: bad MAIL FROM");
goto cleanup;
}
/* And this keep going... RCPT TO, DATA, RSET, QUIT, etc... */
cleanup:
smtp_stream_close(s);
return 0;
I've been reading Postfix sources and it seems they use setjmp/longjmp
for exceptions on . I don't think that's a good approach, so I'm asking
it here. Qmail's approach is to _exit() on most errors, which is ugly.
What would be a 'good' error handling mechanism for this kind of
situation?
Thanks
I'm creating a SMTP application and I would like to hear opinions about
error handling. Currently there are two functions that communicate with
the remote peer:
ssize_t smtp_puts(smtp_stream_t *stream, const char *fmt, ...);
ssize_t smtp_gets(smtp_stream_t *stream, char *buf, size_t len);
Both of them return the number of written bytes to the stream, or -1 if
an error ocurred. The error is set on errno, since they use write() and
read().
My approach is like the following:
if (smtp_puts(s, "HELO hostname") == -1) {
syslog(LOG_ERR, "smtp_puts: sending HELO: %m");
goto cleanup;
}
if (smtp_gets(s, buf, sizeof(buf) == -1) {
syslog(LOG_ERR," smtp_gets: receiving HELO: %m");
goto cleanup;
}
/* Process the HELO response */
if (smtp_check_helo(buf) == -1) {
syslog(LOG_ERR, "smtp_check_helo: bad HELO");
goto cleanup;
}
if (smtp_puts(s, "MAIL FROM:<postmaster>") == -1) {
syslog(LOG_ERR, "smtp_puts: sending MAIL FROM: %m");
goto cleanup;
}
if (smtp_gets(s, buf, sizeof(buf) == -1) {
syslog(LOG_ERR," smtp_gets: receiving MAIL FROM: %m");
goto cleanup;
}
/* Process the MAIL FROM response */
if (smtp_check_mailfrom(buf) == -1) {
syslog(LOG_ERR, "smtp_check_mailfrom: bad MAIL FROM");
goto cleanup;
}
/* And this keep going... RCPT TO, DATA, RSET, QUIT, etc... */
cleanup:
smtp_stream_close(s);
return 0;
I've been reading Postfix sources and it seems they use setjmp/longjmp
for exceptions on . I don't think that's a good approach, so I'm asking
it here. Qmail's approach is to _exit() on most errors, which is ugly.
What would be a 'good' error handling mechanism for this kind of
situation?
Thanks