/* if we're in the midst of processing something, don't die. */
if ( !(dsi->flags & DSI_RUNNING) && (dsi->tickle >= AFPobj->options.timeout)) {
LOG(log_error, logtype_afpd, "afp_alarm: child timed out, entering disconnected state");
- dsi->proto_close(dsi);
- dsi->flags |= DSI_DISCONNECTED;
+ (void)dsi_disconnect(dsi);
return;
}
err = dsi_tickle(AFPobj->handle);
if (err <= 0) {
LOG(log_error, logtype_afpd, "afp_alarm: connection problem, entering disconnected state");
- dsi->proto_close(dsi);
- dsi->flags |= DSI_DISCONNECTED;
+ (void)dsi_disconnect(dsi);
}
}
continue;
}
/* Some error on the client connection, enter disconnected state */
- dsi->flags |= DSI_DISCONNECTED;
+ (void)dsi_disconnect(dsi);
/* the client sometimes logs out (afp_logout) but doesn't close the DSI session */
if (dsi->flags & DSI_AFP_LOGGED_OUT) {
if (!dsi_cmdreply(dsi, err)) {
LOG(log_error, logtype_afpd, "dsi_cmdreply(%d): %s", dsi->socket, strerror(errno) );
- dsi->flags |= DSI_DISCONNECTED;
+ (void)dsi_disconnect(dsi);
}
break;
if (!dsi_wrtreply(dsi, err)) {
LOG(log_error, logtype_afpd, "dsi_wrtreply: %s", strerror(errno) );
- dsi->flags |= DSI_DISCONNECTED;
+ (void)dsi_disconnect(dsi);
}
break;
extern size_t dsi_stream_read (DSI *, void *, const size_t);
extern int dsi_stream_send (DSI *, void *, size_t);
extern int dsi_stream_receive (DSI *, void *, const size_t, size_t *);
+extern int dsi_disconnect(DSI *dsi);
#ifdef WITH_SENDFILE
extern ssize_t dsi_stream_read_file(DSI *, int, off_t off, const size_t len);
return 0;
}
+/*!
+ * Communication error with the client, enter disconnected state
+ *
+ * 1. close the socket
+ * 2. set the DSI_DISCONNECTED flag
+ */
+int dsi_disconnect(DSI *dsi)
+{
+ dsi->proto_close(dsi); /* 1 */
+ dsi->flags |= DSI_DISCONNECTED; /* 2 */
+ return 0;
+}
+
/* ------------------------------
* write raw data. return actual bytes read. checks against EINTR
* aren't necessary if all of the signals have SA_RESTART
}
/* now get the remaining data */
- len += dsi_stream_read(dsi, data + len, length - len);
+ if ((buflen = dsi_stream_read(dsi, data + len, length - len)) != length - len)
+ return 0;
+ len += buflen;
+
return len;
}