port mapper updates

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3137 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-10-28 10:37:32 +00:00
parent 4699862287
commit 766b053b50
2 changed files with 189 additions and 142 deletions

View file

@ -1,3 +1,11 @@
Wed Oct 28 11:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Tools/gdomap.c: Added command-line options to lookup, register, and
unregister a name for a port - basically for debugging purposes.
* src/TcpPort.m: Modified port registration code to cope with the
case where a server dies and is restarted, and tries to use the
same ip port number it has before it died.
Tue Oct 27 08:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Tue Oct 27 08:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Corrected all the collection classes to return the count of objects Corrected all the collection classes to return the count of objects
@ -6,29 +14,29 @@ Tue Oct 27 08:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Mon Oct 26 10:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Mon Oct 26 10:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
src/NSGCString.m: Implemented ([-copy]) and ([-copyWithZone:]) to * src/NSGCString.m: Implemented ([-copy]) and ([-copyWithZone:]) to
work without invoking any methods uing the runtime - much faster. work without invoking any methods uing the runtime - much faster.
src/NSObject.m: Bugfix and performance improvement to the -perform... * src/NSObject.m: Bugfix and performance improvement to the -perform...
methods. They previously threw an exception if the method referred methods. They previously threw an exception if the method referred
to by the selector was not implemented (when they should have tried to by the selector was not implemented (when they should have tried
forwarding instead) rather than when passed a nul selector. forwarding instead) rather than when passed a nul selector.
Sun Oct 25 08:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Sun Oct 25 08:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
src/NSObject.m: Cache implementation for adding object to autorelease * src/NSObject.m: Cache implementation for adding object to autorelease
pool to avoid objc runtime messaging overhead. pool to avoid objc runtime messaging overhead.
src/NSAutoreleasePool.m: Cache implementation for adding object to * src/NSAutoreleasePool.m: Cache implementation for adding object to
src/NSAutoreleasePool.m: Cache implementation for adding object to * src/NSAutoreleasePool.m: Cache implementation for adding object to
autorelease pool to avoid objc runtime messaging overhead. autorelease pool to avoid objc runtime messaging overhead.
src/NSGCString.m: Implemented ([+allocWithZone:]) * src/NSGCString.m: Implemented ([+allocWithZone:])
src/NSGString.m: Implemented ([+allocWithZone:]) * src/NSGString.m: Implemented ([+allocWithZone:])
Sat Oct 24 11:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Sat Oct 24 11:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
src/NSArchiver.m: New implementation * src/NSArchiver.m: New implementation
src/NSArchiver.m: New file * src/NSArchiver.m: New file
src/GNUmakefile: Added NSUnarchiver.m * src/GNUmakefile: Added NSUnarchiver.m
src/include/NSArchiver.h: New version * src/include/NSArchiver.h: New version
New Archiver/unarchiver - OPENSTEP complient (I think). New Archiver/unarchiver - OPENSTEP complient (I think).
Basic functionality tested fairly thoroughly, some of the more Basic functionality tested fairly thoroughly, some of the more
unusual bits untested so far. Mechanisms for adding other backends unusual bits untested so far. Mechanisms for adding other backends
@ -38,29 +46,29 @@ Sat Oct 24 11:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Thu Oct 22 21:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Thu Oct 22 21:45:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
src/NSData.m: Added support for serialisation of Class and SEL types * src/NSData.m: Added support for serialisation of Class and SEL types
and made a more efficient version of the main deserialisation code and made a more efficient version of the main deserialisation code
int the NSDataStatic class. in the NSDataStatic class.
Wed Oct 21 13:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Wed Oct 21 13:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
src/NSData.m: Reorganized and optimised. * src/NSData.m: Reorganized and optimised.
src/NSGArray.m: optimised coding/decoding * src/NSGArray.m: optimised coding/decoding
src NSGCountedSet.m: optimised coding/decoding * src/NSGCountedSet.m: optimised coding/decoding
src/NSGDictionary.m: optimised coding/decoding * src/NSGDictionary.m: optimised coding/decoding
src/NSGSet.m: optimised coding/decoding * src/NSGSet.m: optimised coding/decoding
src/NSObject.m: cache data classes * src/NSObject.m: cache data classes
src/NSString.m: Added (nonstandard) ([-boolValue]) method * src/NSString.m: Added (nonstandard) ([-boolValue]) method
src/include/NSData.h: Added ([-relinquishAllocatedBytesFromZone:]) * src/include/NSData.h: Added ([-relinquishAllocatedBytesFromZone:])
src/include/NSString.h: Added (nonstandard) ([-boolValue]) method * src/include/NSString.h: Added (nonstandard) ([-boolValue]) method
src/include/NSPortMessage.h: Added (as yet unused) class. * src/include/NSPortMessage.h: Added (as yet unused) class.
src/NSPortMessage.m: Added (as yet unused) skeleton implementation. * src/NSPortMessage.m: Added (as yet unused) skeleton implementation.
Thu Oct 17 08:15:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Thu Oct 17 08:15:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
src/NSGDictionary.m: Added checks for invalid parameters. * src/NSGDictionary.m: Added checks for invalid parameters.
src/NSGSet.m: Added checks for invalid parameters. * src/NSGSet.m: Added checks for invalid parameters.
src/NSGCountedSet.m: Added checks for invalid parameters. * src/NSGCountedSet.m: Added checks for invalid parameters.
Thu Oct 15 08:13:12 1998 Masatake Yamato <masata-y@is.aist-nara.ac.jp> Thu Oct 15 08:13:12 1998 Masatake Yamato <masata-y@is.aist-nara.ac.jp>

View file

@ -502,159 +502,198 @@ nameFail(int why)
static int static int
nameServer(const char* name, const char* host, int op, struct sockaddr_in* addr, int pnum, int max) nameServer(const char* name, const char* host, int op, struct sockaddr_in* addr, int pnum, int max)
{ {
struct sockaddr_in sin; struct sockaddr_in sin;
struct servent* sp; struct servent* sp;
struct hostent* hp; struct hostent* hp;
unsigned short p = htons(GDOMAP_PORT); unsigned short p = htons(GDOMAP_PORT);
unsigned short port = 0; unsigned short port = 0;
int len = strlen(name); int len = strlen(name);
int multi = 0; int multi = 0;
int found = 0; int found = 0;
int rval; int rval;
char local_hostname[MAXHOSTNAMELEN]; char local_hostname[MAXHOSTNAMELEN];
if (len == 0) { if (len == 0)
[NSException raise: NSInternalInconsistencyException {
format: @"no name specified"]; [NSException raise: NSInternalInconsistencyException
format: @"no name specified"];
} }
if (len > 255) { if (len > 255)
[NSException raise: NSInternalInconsistencyException {
format: @"name length to large (>255 characters)"]; [NSException raise: NSInternalInconsistencyException
format: @"name length to large (>255 characters)"];
} }
#if GDOMAP_PORT_OVERRIDE #if GDOMAP_PORT_OVERRIDE
p = htons(GDOMAP_PORT_OVERRIDE); p = htons(GDOMAP_PORT_OVERRIDE);
#else #else
/* /*
* Ensure we have port number to connect to name server. * Ensure we have port number to connect to name server.
* The TCP service name 'gdomap' overrides the default port. * The TCP service name 'gdomap' overrides the default port.
*/ */
if ((sp = getservbyname("gdomap", "tcp")) != 0) { if ((sp = getservbyname("gdomap", "tcp")) != 0)
p = sp->s_port; /* Network byte order. */ {
p = sp->s_port; /* Network byte order. */
} }
#endif #endif
/* /*
* The host name '*' matches any host on the local network. * The host name '*' matches any host on the local network.
*/ */
if (host && host[0] == '*' && host[1] == '\0') { if (host && host[0] == '*' && host[1] == '\0')
multi = 1; {
multi = 1;
} }
/* /*
* If no host name is given, we use the name of the local host. * If no host name is given, we use the name of the local host.
* NB. This should always be the case for operations other than lookup. * NB. This should always be the case for operations other than lookup.
*/ */
if (multi || host == 0 || *host == '\0') { if (multi || host == 0 || *host == '\0')
char *first_dot; {
char *first_dot;
if (gethostname(local_hostname, sizeof(local_hostname)) < 0) { if (gethostname(local_hostname, sizeof(local_hostname)) < 0)
[NSException raise: NSInternalInconsistencyException {
format: @"gethostname() failed: %s", strerror(errno)]; [NSException raise: NSInternalInconsistencyException
format: @"gethostname() failed: %s", strerror(errno)];
} }
first_dot = strchr(local_hostname, '.'); first_dot = strchr(local_hostname, '.');
if (first_dot) { if (first_dot)
*first_dot = '\0'; {
*first_dot = '\0';
} }
host = local_hostname; host = local_hostname;
} }
if ((hp = gethostbyname(host)) == 0) { if ((hp = gethostbyname(host)) == 0)
[NSException raise: NSInternalInconsistencyException {
format: @"get host address for %s", host]; [NSException raise: NSInternalInconsistencyException
format: @"get host address for %s", host];
} }
if (hp->h_addrtype != AF_INET) { if (hp->h_addrtype != AF_INET)
[NSException raise: NSInternalInconsistencyException {
format: @"non-internet network not supported for %s", host]; [NSException raise: NSInternalInconsistencyException
format: @"non-internet network not supported for %s", host];
} }
memset((char*)&sin, '\0', sizeof(sin)); memset((char*)&sin, '\0', sizeof(sin));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = p; sin.sin_port = p;
memcpy((caddr_t)&sin.sin_addr, hp->h_addr, hp->h_length); memcpy((caddr_t)&sin.sin_addr, hp->h_addr, hp->h_length);
if (multi) { if (multi)
unsigned short num; {
struct in_addr* b; unsigned short num;
struct in_addr* b;
/* /*
* A host name of '*' is a special case which should do lookup on * A host name of '*' is a special case which should do lookup on
* all machines on the local network until one is found which has * all machines on the local network until one is found which has
* the specified server on it. * the specified server on it.
*/ */
rval = tryHost(GDO_SERVERS, 0, 0, &sin, &num, (unsigned char**)&b); rval = tryHost(GDO_SERVERS, 0, 0, &sin, &num, (unsigned char**)&b);
/* /*
* If the connection to the local name server fails, * If the connection to the local name server fails,
* attempt to start it us and retry the lookup. * attempt to start it us and retry the lookup.
*/ */
if (rval != 0 && host == local_hostname) { if (rval != 0 && host == local_hostname)
system(make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX)); {
sleep(5); system(make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX));
rval = tryHost(GDO_SERVERS, 0, 0, &sin, &num, (unsigned char**)&b); sleep(5);
rval = tryHost(GDO_SERVERS, 0, 0, &sin, &num, (unsigned char**)&b);
} }
if (rval == 0) { if (rval == 0)
int i; {
int i;
for (i = 0; found == 0 && i < num; i++) { for (i = 0; found == 0 && i < num; i++)
memset((char*)&sin, '\0', sizeof(sin)); {
sin.sin_family = AF_INET; memset((char*)&sin, '\0', sizeof(sin));
sin.sin_port = p; sin.sin_family = AF_INET;
memcpy((caddr_t)&sin.sin_addr, &b[i], sizeof(struct in_addr)); sin.sin_port = p;
if (sin.sin_addr.s_addr == 0) continue; memcpy((caddr_t)&sin.sin_addr, &b[i], sizeof(struct in_addr));
if (sin.sin_addr.s_addr == 0)
continue;
if (tryHost(GDO_LOOKUP, len, name, &sin, &port, 0) == 0) { if (tryHost(GDO_LOOKUP, len, name, &sin, &port, 0) == 0)
if (port != 0) { {
memset((char*)&addr[found], '\0', sizeof(*addr)); if (port != 0)
memcpy((caddr_t)&addr[found].sin_addr, &sin.sin_addr, {
memset((char*)&addr[found], '\0', sizeof(*addr));
memcpy((caddr_t)&addr[found].sin_addr, &sin.sin_addr,
sizeof(sin.sin_addr)); sizeof(sin.sin_addr));
addr[found].sin_family = AF_INET; addr[found].sin_family = AF_INET;
addr[found].sin_port = htons(port); addr[found].sin_port = htons(port);
found++; found++;
if (found == max) { if (found == max)
break; {
break;
} }
} }
} }
} }
objc_free(b); objc_free(b);
return(found); return(found);
} }
else { else
nameFail(rval); {
nameFail(rval);
} }
} }
else { else
if (op == GDO_REGISTER) { {
port = (unsigned short)pnum; if (op == GDO_REGISTER)
{
port = (unsigned short)pnum;
} }
rval = tryHost(op, len, name, &sin, &port, 0); rval = tryHost(op, len, name, &sin, &port, 0);
/* /*
* If the connection to the local name server fails, * If the connection to the local name server fails,
* attempt to start it us and retry the lookup. * attempt to start it us and retry the lookup.
*/ */
if (rval != 0 && host == local_hostname) { if (rval != 0 && host == local_hostname)
system(make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX)); {
sleep(5); system(make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX));
if (op == GDO_REGISTER) { sleep(5);
port = (unsigned short)pnum; if (op == GDO_REGISTER)
{
port = (unsigned short)pnum;
} }
rval = tryHost(op, len, name, &sin, &port, 0); rval = tryHost(op, len, name, &sin, &port, 0);
} }
nameFail(rval); nameFail(rval);
} }
if (op == GDO_REGISTER) { if (op == GDO_REGISTER)
if (port == 0 || (pnum != 0 && port != pnum)) { {
[NSException raise: NSInternalInconsistencyException if (port == 0 || (pnum != 0 && port != pnum))
format: @"service already registered"]; {
/*
* If the name server thinks we are already registered on this
* port, we must have crashed, restarted, and got the same port
* number we used to have before we crashed. The solution is to
* unregister our name from the port and retry the registration.
*/
rval = tryHost(GDO_UNREG, len, name, &sin, &port, 0);
nameFail(rval);
port = (unsigned short)pnum;
rval = tryHost(op, len, name, &sin, &port, 0);
nameFail(rval);
if (port == 0 || (pnum != 0 && port != pnum))
{
[NSException raise: NSInternalInconsistencyException
format: @"service already registered"];
}
} }
} }
if (port == 0) { if (port == 0)
return 0; {
return 0;
} }
memset((char*)addr, '\0', sizeof(*addr)); memset((char*)addr, '\0', sizeof(*addr));
memcpy((caddr_t)&addr->sin_addr, &sin.sin_addr, sizeof(sin.sin_addr)); memcpy((caddr_t)&addr->sin_addr, &sin.sin_addr, sizeof(sin.sin_addr));
addr->sin_family = AF_INET; addr->sin_family = AF_INET;
addr->sin_port = htons(port); addr->sin_port = htons(port);
return 1; return 1;
} }
#else #else