if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
lprintf(1, "citserver: Can't bind: %s\n", strerror(errno));
- return(-1);
+ sin.sin_port = 0;
+ if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ lprintf(1, "citserver: Can't bind: %s\n",
+ strerror(errno));
+ return(-1);
+ }
+ else {
+ lprintf(1, "bind to alternate port %d ok\n",
+ htons(sin.sin_port) );
+ }
}
if (listen(s, queue_len) < 0) {
free(moddir);
}
- lprintf(7, "Starting housekeeper thread\n");
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- if (pthread_create(&HousekeepingThread, &attr,
- (void* (*)(void*)) housekeeping_loop, NULL) != 0) {
- lprintf(1, "Can't create housekeeping thead: %s\n",
- strerror(errno));
- }
-
-
/*
* The rescan pipe exists so that worker threads can be woken up and
* told to re-scan the context list for fd's to listen on. This is
}
}
+ /*
+ * Create the housekeeper thread
+ */
+ lprintf(7, "Starting housekeeper thread\n");
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ if (pthread_create(&HousekeepingThread, &attr,
+ (void* (*)(void*)) housekeeping_loop, NULL) != 0) {
+ lprintf(1, "Can't create housekeeping thead: %s\n",
+ strerror(errno));
+ }
+
+
/*
* Now create a bunch of worker threads.
*/
}
-
-
+/*
+ * Bind a thread to a context.
+ */
+inline void become_session(struct CitContext *which_con) {
+ pthread_setspecific(MyConKey, (void *)which_con );
+}
SO_REUSEADDR,
&i, sizeof(i));
- pthread_setspecific(MyConKey,
- (void *)con);
+ become_session(con);
begin_session(con);
serviceptr->h_greeting_function();
- pthread_setspecific(MyConKey,
- (void *)NULL);
+ become_session(NULL);
con->state = CON_IDLE;
goto SETUP_FD;
}
* thread that the &readfds needs to be refreshed with more
* current data.
*/
- if (FD_ISSET(rescan[0], &readfds)) {
+ if (!time_to_die) if (FD_ISSET(rescan[0], &readfds)) {
read(rescan[0], &junk, 1);
goto SETUP_FD;
}
/* We're bound to a session, now do *one* command */
if (bind_me != NULL) {
- pthread_setspecific(MyConKey, (void *)bind_me);
+ become_session(bind_me);
CC->h_command_function();
- pthread_setspecific(MyConKey, (void *)NULL);
+ become_session(NULL);
bind_me->state = CON_IDLE;
if (bind_me->kill_me == 1) {
RemoveContext(bind_me);