use of it with either dedicated threads or EVT_TIMER hooks.
strcat (sysname, name);
len = cutuserkey(sysname);
memcpy(context->curr_user, sysname, len + 1);
+ context->client_socket = (-1);
/* internal_create_user has the side effect of loading the user regardless of wether they
* already existed or needed to be created
* Citadel Threads API
*/
struct CtdlThreadNode *CtdlThreadCreate(char *name, long flags, void *(*thread_func) (void *arg), void *args);
-struct CtdlThreadNode *CtdlThreadSchedule(char *name, long flags, void *(*thread_func) (void *arg), void *args, time_t when);
void CtdlThreadSleep(int secs);
void CtdlThreadStop(struct CtdlThreadNode *thread);
int CtdlThreadCheckStop(void);
*
* Run through the rooms doing various types of network stuff.
*/
-void *network_do_queue(void *args) {
+void network_do_queue(void) {
static time_t last_run = 0L;
struct RoomProcList *ptr;
int full_processing = 1;
- struct CitContext networkerCC;
-
- /* Give the networker its own private CitContext */
- CtdlFillSystemContext(&networkerCC, "network");
- citthread_setspecific(MyConKey, (void *)&networkerCC );
/*
* Run the full set of processing tasks no more frequently
* with a static variable instead.
*/
if (doing_queue) {
- CtdlClearSystemContext();
- return NULL;
+ return;
}
doing_queue = 1;
}
doing_queue = 0;
-
- /* Reschedule this task to happen again periodically, unless the thread system indicates
- * that the server is shutting down.
- */
- if (!CtdlThreadCheckStop()) {
- CtdlThreadSchedule("IGnet Network", CTDLTHREAD_BIGSTACK,
- network_do_queue, NULL, time(NULL) + 60
- );
- }
- else {
- CtdlLogPrintf(CTDL_DEBUG, "network: Task STOPPED.\n");
- }
- CtdlClearSystemContext();
- return NULL;
}
return 0;
}
+void *ignet_thread(void *arg) {
+ struct CitContext ignet_thread_CC;
+
+ CtdlLogPrintf(CTDL_DEBUG, "ignet_thread() initializing\n");
+ CtdlFillSystemContext(&ignet_thread_CC, "IGnet Queue");
+ citthread_setspecific(MyConKey, (void *)&ignet_thread_CC);
+
+ while (!CtdlThreadCheckStop()) {
+ network_do_queue();
+ CtdlThreadSleep(60);
+ }
+
+ CtdlClearSystemContext();
+ return(NULL);
+}
+
+
+
/*
* Module entry point
CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config");
CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller");
CtdlRegisterProtoHook(cmd_nsyn, "NSYN", "Synchronize room to node");
- CtdlRegisterRoomHook(network_room_handler);
+ CtdlRegisterRoomHook(network_room_handler);
CtdlRegisterCleanupHook(destroy_network_queue_room);
+ CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, ignet_thread, NULL);
}
- else
- CtdlThreadSchedule("IGnet Network", CTDLTHREAD_BIGSTACK, network_do_queue, NULL, 0);
- /* return our Subversion id for the Log */
return "network";
}
/*
* Scan for rooms that have RSS client requests configured
*/
-void *rssclient_scan(void *args) {
+void rssclient_scan(void *args) {
static time_t last_run = 0L;
static int doing_rssclient = 0;
rssnetcfg *rptr = NULL;
CtdlLogPrintf(CTDL_DEBUG, "rssclient ended\n");
last_run = time(NULL);
doing_rssclient = 0;
- if (!CtdlThreadCheckStop())
- CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, last_run + config.c_net_freq);
- else
- CtdlLogPrintf(CTDL_DEBUG, "rssclient: Task STOPPED.\n");
CtdlClearSystemContext();
return NULL;
}
if (threading)
{
CtdlLogPrintf(CTDL_INFO, "%s\n", curl_version());
- CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, 0);
+ CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
}
StartHandlers = NewHash(1, NULL);
int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */
-citthread_mutex_t smtp_send_lock;
-
/*****************************************************************************/
/* SMTP SERVER (INBOUND) STUFF */
/*
- * smtp_do_queue()
+ * smtp_queue_thread()
*
* Run through the queue sending out messages.
*/
-void *smtp_do_queue(void *arg) {
+void *smtp_queue_thread(void *arg) {
int num_processed = 0;
struct CitContext smtp_queue_CC;
CtdlFillSystemContext(&smtp_queue_CC, "SMTP Send");
- citthread_setspecific(MyConKey, (void *)&smtp_queue_CC );
- CtdlLogPrintf(CTDL_INFO, "SMTP client: processing outbound queue\n");
+ citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
+ CtdlLogPrintf(CTDL_DEBUG, "smtp_queue_thread() initializing\n");
- if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
- CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
- }
- else {
- num_processed = CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_do_procmsg, NULL);
- }
+ while (!CtdlThreadCheckStop()) {
+
+ CtdlLogPrintf(CTDL_INFO, "SMTP client: processing outbound queue\n");
- citthread_mutex_unlock (&smtp_send_lock);
- CtdlLogPrintf(CTDL_INFO, "SMTP client: queue run completed; %d messages processed\n", num_processed);
+ if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
+ CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
+ }
+ else {
+ num_processed = CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_do_procmsg, NULL);
+ }
+ CtdlLogPrintf(CTDL_INFO, "SMTP client: queue run completed; %d messages processed\n", num_processed);
+ CtdlThreadSleep(60);
+ }
CtdlClearSystemContext();
return(NULL);
-/*
- * smtp_queue_thread
- *
- * Create a thread to run the SMTP queue
- *
- * This was created as a response to a situation seen on Uncensored where a bad remote was holding
- * up SMTP sending for long times.
- * Converting to a thread does not fix the problem caused by the bad remote but it does prevent
- * the SMTP sending from stopping housekeeping and the EVT_TIMER event system which in turn prevented
- * other things from happening.
- */
-void smtp_queue_thread (void)
-{
- if (citthread_mutex_trylock (&smtp_send_lock)) {
- CtdlLogPrintf(CTDL_DEBUG, "SMTP queue run already in progress\n");
- }
- else {
- CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, smtp_do_queue, NULL);
- }
-}
-
-
-
-void smtp_server_going_down (void)
-{
- CtdlLogPrintf(CTDL_DEBUG, "SMTP module clean up for shutdown.\n");
-
- citthread_mutex_destroy (&smtp_send_lock);
-}
-
-
-
/*****************************************************************************/
/* SMTP UTILITY COMMANDS */
/*****************************************************************************/
CitadelServiceSMTP_LMTP_UNF);
smtp_init_spoolout();
- CtdlRegisterSessionHook(smtp_queue_thread, EVT_TIMER);
CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP);
CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
- CtdlRegisterCleanupHook (smtp_server_going_down);
- citthread_mutex_init (&smtp_send_lock, NULL);
+ CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, smtp_queue_thread, NULL);
}
/* return our Subversion id for the Log */
-/*
- * Internal function to schedule a thread.
- * Must be called from within a S_THREAD_LIST critical section
- */
-CtdlThreadNode *CtdlThreadSchedule(char *name, long flags, void *(*thread_func) (void *arg), void *args, time_t when)
-{
- CtdlThreadNode *this_thread;
-
- if (num_threads >= 32767)
- {
- CtdlLogPrintf(CTDL_EMERG, "Thread system. Thread list full.\n");
- return NULL;
- }
-
- this_thread = malloc(sizeof(CtdlThreadNode));
- if (this_thread == NULL) {
- CtdlLogPrintf(CTDL_EMERG, "Thread system, can't allocate CtdlThreadNode, exiting\n");
- return NULL;
- }
- /* Initialise the thread structure */
- if (ctdl_internal_init_thread_struct(this_thread, flags) == NULL)
- {
- free(this_thread);
- CtdlLogPrintf(CTDL_EMERG, "Thread system, can't initialise CtdlThreadNode, exiting\n");
- return NULL;
- }
-
- /*
- * If we got here we are going to create the thread so we must initilise the structure
- * first because most implimentations of threading can't create it in a stopped state
- * and it might want to do things with its structure that aren't initialised otherwise.
- */
- if(name)
- {
- this_thread->name = name;
- }
- else
- {
- this_thread->name = "Un-named Thread";
- }
-
- this_thread->flags = flags;
- this_thread->thread_func = thread_func;
- this_thread->user_args = args;
-
- /*
- * When to start this thread
- */
- this_thread->when = when;
-
- begin_critical_section(S_SCHEDULE_LIST);
- this_thread->next = CtdlThreadSchedList;
- CtdlThreadSchedList = this_thread;
- if (this_thread->next)
- this_thread->next->prev = this_thread;
- end_critical_section(S_SCHEDULE_LIST);
-
- return this_thread;
-}
-
-
-
CtdlThreadNode *ctdl_thread_internal_start_scheduled (CtdlThreadNode *this_thread)
{
int ret = 0;