- again:
-
- if (timeout >= 0) {
- to.tv_sec = timeout / 1000;
- to.tv_usec = (timeout % 1000) * 1000;
- } else {
- to.tv_sec = SMBD_SELECT_TIMEOUT;
- to.tv_usec = 0;
- }
-
- /*
- * Note that this call must be before processing any SMB
- * messages as we need to synchronously process any messages
- * we may have sent to ourselves from the previous SMB.
- */
- message_dispatch(smbd_messaging_context());
-
- /*
- * Check to see if we already have a message on the deferred open queue
- * and it's time to schedule.
- */
- if(deferred_open_queue != NULL) {
- bool pop_message = False;
- struct pending_message_list *msg = deferred_open_queue;
-
- if (timeval_is_zero(&msg->end_time)) {
- pop_message = True;
- } else {
- struct timeval tv;
- SMB_BIG_INT tdif;
-
- GetTimeOfDay(&tv);
- tdif = usec_time_diff(&msg->end_time, &tv);
- if (tdif <= 0) {
- /* Timed out. Schedule...*/
- pop_message = True;
- DEBUG(10,("receive_message_or_smb: queued message timed out.\n"));
- } else {
- /* Make a more accurate select timeout. */
- to.tv_sec = tdif / 1000000;
- to.tv_usec = tdif % 1000000;
- DEBUG(10,("receive_message_or_smb: select with timeout of [%u.%06u]\n",
- (unsigned int)to.tv_sec, (unsigned int)to.tv_usec ));
- }
- }
-
- if (pop_message) {
-
- *buffer = (char *)talloc_memdup(mem_ctx, msg->buf.data,
- msg->buf.length);
- if (*buffer == NULL) {
- DEBUG(0, ("talloc failed\n"));
- set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR);
- return False;
- }
- *buffer_len = msg->buf.length;
- *p_encrypted = msg->encrypted;
-
- /* We leave this message on the queue so the open code can
- know this is a retry. */
- DEBUG(5,("receive_message_or_smb: returning deferred open smb message.\n"));
- return True;
- }
- }