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) {
}
-
-
+/*
+ * 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;
}
/* 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);