I've read source code again.
In nsd/binder.c, I've modified it as followings:
static void
PreBind(char *line)
{
Tcl_HashEntry *hPtr;
int new, sock, port;
struct sockaddr_in sa;
char *err, *ent, *p, *q, *addr, *baddr;
Ns_Log(Warning, "DEBUG:PreBind: called: %s", line);
ent = line;
do {
p = strchr(ent, ',');
... [snip] ....
Ns_Log(Warning, "DEBUG:PreBind: baddr: %s, port: %d", baddr, port);
if (port == 0) {
err = "invalid port";
} else if (Ns_GetSockAddr(&sa, baddr, port) != NS_OK) {
err = "invalid address";
} else {
Ns_Log(Warning, "DEBUG:PreBind: Ns_GetSockAddr success");
hPtr = Tcl_CreateHashEntry(&prebound, (char *) &sa, &new);
if (!new) {
err = "duplicate entry";
} else if ((sock = Ns_SockBind(&sa)) == -1) {
Tcl_DeleteHashEntry(hPtr);
err = strerror(errno);
} else {
Ns_Log(Warning, "DEBUG:PreBind: Tcl_SetHashValue(%d)", sock);
Tcl_SetHashValue(hPtr, sock);
err = NULL;
}
}
...[snip] ....
} while (ent != NULL);
}
here is a log:
bin/nsd -ft config.tcl -u www -g www -b 10.0.0.6:80
[21/Feb/2004:18:05:50][44530.134557696][-main-] Warning: DEBUG:PreBind: called:
10.0.0.6:80
[21/Feb/2004:18:05:50][44530.134557696][-main-] Warning: DEBUG:PreBind: baddr:
10.0.0.6, port: 80
[21/Feb/2004:18:05:50][44530.134557696][-main-] Warning: DEBUG:PreBind: Ns_GetSockAddr
success
[21/Feb/2004:18:05:50][44530.134557696][-main-] Warning: DEBUG:PreBind:
Tcl_SetHashValue(3)
[21/Feb/2004:18:05:50][44530.134557696][-main-] Notice: prebind:
bound: 10.0.0.6:80
It's seem work fine. the code entries socket to hash table.
Next, Ns_SockListenEx().
int
Ns_SockListenEx(char *address, int port, int backlog)
{
int err, sock = -1;
struct sockaddr_in sa;
Tcl_HashEntry *hPtr;
Ns_Log(Warning, "DEBUG:SockListenEx: called: %s:%d", address, port);
if (Ns_GetSockAddr(&sa, address, port) != NS_OK) {
Ns_Log(Warning, "DEBUG:SockListenEx: Ns_GetSockAddr return err");
return -1;
}
Ns_MutexLock(&lock);
hPtr = Tcl_FindHashEntry(&prebound, (char *) &sa);
Ns_Log(Warning, "DEBUG:SockListenEx: call Tcl_FindHashEntry");
if (hPtr != NULL) {
sock = (int) Tcl_GetHashValue(hPtr);
Ns_Log(Warning, "DEBUG:SockListenEx: Find socket:%d", sock);
Tcl_DeleteHashEntry(hPtr);
}
Ns_MutexUnlock(&lock);
if (hPtr == NULL) {
Ns_Log(Warning, "DEBUG:SockListenEx: can not Find socket");
sock = Ns_SockBind(&sa);
Ns_Log(Warning, "DEBUG:SockListenEx: socket: %d", sock);
}
if (sock != -1 && listen(sock, backlog) != 0) {
err = errno;
Ns_Log(Warning, "DEBUG:SockListenEx: can not listen: %d", err);
close(sock);
errno = err;
sock = -1;
}
return sock;
}
Here is a log output:
[21/Feb/2004:18:05:50][44530.134560768][-nssock:driver-] Warning: DEBUG:SockListenEx:
called: 10.0.0.6:80
[21/Feb/2004:18:05:50][44530.134560768][-nssock:driver-] Warning: DEBUG:SockListenEx:
call Tcl_FindHashEntry
[21/Feb/2004:18:05:50][44530.134560768][-nssock:driver-] Warning: DEBUG:SockListenEx:
can not Find socket
[21/Feb/2004:18:05:50][44530.134560768][-nssock:driver-] Warning: DEBUG:SockListenEx:
socket: -1
[21/Feb/2004:18:05:50][44530.134560768][-nssock:driver-] Fatal:
nssock: failed to listen on 10.0.0.6:80: Permission denied
Tcl_FindHashEntry() is seem fail. Why ?
I think key value may be incorrect.
Thanks.
---
T.Taguchi.
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of
your email blank.