Skip to content
Snippets Groups Projects
mailsrvr.c 81.4 KiB
Newer Older

			smtp->socket=client_socket;
			smtp->client_addr=client_addr;
			_beginthread (smtp_thread, 0, smtp);
		}

		if(FD_ISSET(pop3_socket,&socket_set)) {

			client_addr_len = sizeof (client_addr);
			client_socket = accept(pop3_socket, (struct sockaddr *)&client_addr
        		,&client_addr_len);

			if (client_socket == INVALID_SOCKET)
			{
rswindell's avatar
rswindell committed
				if(ERROR_VALUE == ENOTSOCK)
            		lprintf("%04d POP3 socket closed while listening",pop3_socket);
					lprintf("%04d !ERROR %d accept failed", pop3_socket, ERROR_VALUE);
				break;
			}
			if(startup->socket_open!=NULL)
				startup->socket_open(TRUE);
			sockets++;

			if(active_clients>=startup->max_clients) {
				lprintf("%04d !MAXMIMUM CLIENTS (%u) reached, access denied"
					,client_socket, startup->max_clients);
				sockprintf(client_socket,"-ERR Maximum active clients reached, please try again later.");
				mswait(3000);
				continue;
			}


			l=1;

			if((i=ioctlsocket(client_socket, FIONBIO, &l))!=0) {
				lprintf("%04d !ERROR %d (%d) disabling blocking on socket"
					,client_socket, i, ERROR_VALUE);
				sockprintf(client_socket,"-ERR System error, please try again later.");
				mswait(3000);
				continue;
			}

			if((pop3=malloc(sizeof(pop3_t)))==NULL) {
				lprintf("%04d !ERROR allocating %u bytes of memory for pop3_t"
					,client_socket,sizeof(pop3_t));
				sockprintf(client_socket,"-ERR System error, please try again later.");
				mswait(3000);
				continue;
			}

			pop3->socket=client_socket;
			pop3->client_addr=client_addr;

			_beginthread (pop3_thread, 0, pop3);
		}
	}

	if(active_clients) {
		lprintf("0000 Waiting for %d active clients to disconnect...", active_clients);
		start=time(NULL);
		while(active_clients) {
			if(time(NULL)-start>TIMEOUT_THREAD_WAIT) {
				lprintf("!TIMEOUT waiting for %u active clients ",active_clients);
				break;
			}
			mswait(100);
		lprintf("0000 Waiting for SendMail thread to terminate...");
		start=time(NULL);
		while(sendmail_running) {
			if(time(NULL)-start>TIMEOUT_THREAD_WAIT) {
				lprintf("!TIMEOUT waiting for sendmail thread to "
            		"terminate");
				break;
			}
			mswait(100);