mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Retain/Release and DO patches from Richard Frith-MacDonald
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2571 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6a21926d00
commit
d88b91f6bb
25 changed files with 697 additions and 134 deletions
|
@ -40,7 +40,6 @@ extern NSString* NSLoadedClasses;
|
|||
NSArray* _bundleClasses;
|
||||
Class _principalClass;
|
||||
id _infoDict;
|
||||
unsigned int _retainCount;
|
||||
unsigned int _bundleType;
|
||||
BOOL _codeLoaded;
|
||||
unsigned int _version;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <Foundation/NSRange.h>
|
||||
#include <Foundation/NSSerialization.h>
|
||||
|
||||
@interface NSData : NSObject <NSCopying, NSMutableCopying>
|
||||
@interface NSData : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
||||
|
||||
// Allocating and Initializing a Data Object
|
||||
|
||||
|
|
|
@ -213,4 +213,22 @@ typedef double NSTimeInterval;
|
|||
|
||||
@end
|
||||
|
||||
@interface NSCalendarDate (OPENSTEP)
|
||||
|
||||
- (NSCalendarDate *)dateByAddingYears:(int)years
|
||||
months:(int)months
|
||||
days:(int)days
|
||||
hours:(int)hours
|
||||
minutes:(int)minutes
|
||||
seconds:(int)seconds;
|
||||
|
||||
- (void) years: (int*)years
|
||||
months: (int*)months
|
||||
days: (int*)days
|
||||
hours: (int*)hours
|
||||
minutes: (int*)minutes
|
||||
seconds: (int*)seconds
|
||||
sinceDate: (NSDate*)date;
|
||||
@end
|
||||
|
||||
#endif /* __NSDate_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
2
Makefile
2
Makefile
|
@ -46,7 +46,7 @@ DIST_FILES = \
|
|||
#
|
||||
# The list of subproject directories
|
||||
#
|
||||
SUBPROJECTS = src doc checks examples NSCharacterSets NSTimeZones admin
|
||||
SUBPROJECTS = Tools src doc checks examples NSCharacterSets NSTimeZones admin
|
||||
|
||||
-include Makefile.preamble
|
||||
|
||||
|
|
|
@ -69,7 +69,8 @@ after-uninstall::
|
|||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
# after-distclean::
|
||||
after-distclean::
|
||||
rm -rf NSTimeZones
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include <Foundation/NSMapTable.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
|
@ -262,7 +263,8 @@ static BOOL debug_coder = NO;
|
|||
{
|
||||
id ret = [[self class] newReadingFromStream:
|
||||
[MemoryStream streamWithData:data]];
|
||||
if ([self retainCount] == 0)
|
||||
if ([self retainCount]
|
||||
- [[[self class] autoreleaseClass] autoreleaseCountForObject:self] == 0)
|
||||
[ret autorelease];
|
||||
else
|
||||
[self release];
|
||||
|
|
|
@ -375,7 +375,6 @@ hpux-load.h \
|
|||
null-load.h \
|
||||
simple-load.h \
|
||||
NSCallBacks.h \
|
||||
gdomap.c gdomap.h \
|
||||
tzfile.h
|
||||
|
||||
BASE_HEADERS = \
|
||||
|
|
|
@ -70,7 +70,10 @@ after-uninstall::
|
|||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
# after-distclean::
|
||||
after-distclean::
|
||||
rm -f include/config.h include/dynamic-load.h \
|
||||
Foundation gnustep/base \
|
||||
NSNumber[0-9]*.m NSValue[0-9]*.m
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -365,8 +366,8 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
|||
format: @"Bundle for path %@ released too many times", _path];
|
||||
}
|
||||
|
||||
NSParameterAssert(_retainCount >= 0);
|
||||
if (_retainCount == 0)
|
||||
if ([self retainCount]
|
||||
- [[[self class] autoreleaseClass] autoreleaseCountForObject:self] == 0)
|
||||
{
|
||||
/* Cache all bundles */
|
||||
if (_bundleType == NSBUNDLE_APPLICATION
|
||||
|
@ -380,18 +381,7 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
|||
[self dealloc];
|
||||
return;
|
||||
}
|
||||
_retainCount--;
|
||||
}
|
||||
|
||||
- retain
|
||||
{
|
||||
_retainCount++;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (unsigned) retainCount
|
||||
{
|
||||
return _retainCount;
|
||||
[super release];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
|
|
@ -74,10 +74,30 @@ static id long_month[12] = {@"January",
|
|||
@"October",
|
||||
@"November",
|
||||
@"December"};
|
||||
static id short_day[7] = {@"Sun",
|
||||
@"Mon",
|
||||
@"Tue",
|
||||
@"Wed",
|
||||
@"Thu",
|
||||
@"Fri",
|
||||
@"Sat"};
|
||||
static id long_day[7] = {@"Sunday",
|
||||
@"Monday",
|
||||
@"Tuesday",
|
||||
@"Wednesday",
|
||||
@"Thursday",
|
||||
@"Friday",
|
||||
@"Saturday"};
|
||||
|
||||
@interface NSCalendarDate (Private)
|
||||
|
||||
- (void)getYear:(int *)year month:(int *)month day:(int *)day
|
||||
hour:(int *)hour minute:(int *)minute second:(int *)second;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSCalendarDate
|
||||
|
||||
|
||||
//
|
||||
// Getting an NSCalendar Date
|
||||
//
|
||||
|
@ -345,11 +365,13 @@ static id long_month[12] = {@"January",
|
|||
second:(unsigned int)second
|
||||
timeZone:(NSTimeZone *)aTimeZone
|
||||
{
|
||||
int a;
|
||||
int a;
|
||||
int c;
|
||||
NSTimeInterval s;
|
||||
|
||||
a = [self absoluteGregorianDay: day month: month year: year];
|
||||
|
||||
// Calculate date as GMT
|
||||
a -= GREGORIAN_REFERENCE;
|
||||
s = (double)a * 86400;
|
||||
s += hour * 3600;
|
||||
|
@ -361,7 +383,69 @@ static id long_month[12] = {@"January",
|
|||
timeZoneDetailForDate:
|
||||
[NSDate dateWithTimeIntervalSinceReferenceDate: s]];
|
||||
|
||||
return [self initWithTimeIntervalSinceReferenceDate: s];
|
||||
// Adjust date so it is correct for time zone.
|
||||
s -= [time_zone timeZoneSecondsFromGMT];
|
||||
self = [self initWithTimeIntervalSinceReferenceDate: s];
|
||||
|
||||
/* Now permit up to five cycles of adjustment to allow for daylight savings.
|
||||
NB. this depends on it being OK to call the
|
||||
[-initWithTimeIntervalSinceReferenceDate:] method repeatedly! */
|
||||
|
||||
for (c = 0; c < 5 && self != nil; c++)
|
||||
{
|
||||
int y, m, d, h, mm, ss;
|
||||
NSTimeZoneDetail *z;
|
||||
|
||||
[self getYear: &y month: &m day: &d hour: &h minute: &mm second: &ss];
|
||||
if (y==year && m==month && d==day && h==hour && mm==minute && ss==second)
|
||||
return self;
|
||||
|
||||
/* Has the time-zone detail changed? If so - adjust time for it,
|
||||
other wise - try to adjust to the correct time. */
|
||||
z = [aTimeZone
|
||||
timeZoneDetailForDate:
|
||||
[NSDate dateWithTimeIntervalSinceReferenceDate: s]];
|
||||
if (z != time_zone)
|
||||
{
|
||||
NSTimeInterval oldOffset;
|
||||
NSTimeInterval newOffset;
|
||||
|
||||
oldOffset = [time_zone timeZoneSecondsFromGMT];
|
||||
time_zone = z;
|
||||
newOffset = [time_zone timeZoneSecondsFromGMT];
|
||||
s += oldOffset - newOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSTimeInterval move;
|
||||
|
||||
/* Do we need to go back or forwards in time?
|
||||
Shift at most two hours - we know of no daylight savings time
|
||||
which is an offset of more than two hourts */
|
||||
if (y > year)
|
||||
move = -7200.0;
|
||||
else if (y < year)
|
||||
move = +7200.0;
|
||||
else if (m > month)
|
||||
move = -7200.0;
|
||||
else if (m < month)
|
||||
move = +7200.0;
|
||||
else if (d > day)
|
||||
move = -7200.0;
|
||||
else if (d < day)
|
||||
move = +7200.0;
|
||||
else if (h > hour || h < hour)
|
||||
move = (hour - h)*3600.0;
|
||||
else if (mm > minute || mm < minute)
|
||||
move = (minute - mm)*60.0;
|
||||
else
|
||||
move = (second - ss);
|
||||
|
||||
s += move;
|
||||
}
|
||||
self = [self initWithTimeIntervalSinceReferenceDate: s];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// Default initializer
|
||||
|
@ -428,7 +512,16 @@ static id long_month[12] = {@"January",
|
|||
|
||||
- (int)dayOfWeek
|
||||
{
|
||||
return 0;
|
||||
int d = [self dayOfCommonEra];
|
||||
|
||||
/* The era started on a sunday.
|
||||
Did we always have a seven day week?
|
||||
Did we lose week days changing from Julian to Gregorian?
|
||||
AFAIK seven days a week is ok for all reasonable dates. */
|
||||
d = d % 7;
|
||||
if (d < 0)
|
||||
d += 7;
|
||||
return d;
|
||||
}
|
||||
|
||||
- (int)dayOfYear
|
||||
|
@ -531,7 +624,12 @@ static id long_month[12] = {@"January",
|
|||
minute:(unsigned int)minute
|
||||
second:(unsigned int)second
|
||||
{
|
||||
return self;
|
||||
return [self dateByAddingYears: year
|
||||
months: month
|
||||
days: day
|
||||
hours: hour
|
||||
minutes: minute
|
||||
seconds: second];
|
||||
}
|
||||
|
||||
// Getting String Descriptions of Dates
|
||||
|
@ -555,16 +653,17 @@ static id long_month[12] = {@"January",
|
|||
const char *f = [format cString];
|
||||
int lf = strlen(f);
|
||||
BOOL mtag = NO, dtag = NO, ycent = NO;
|
||||
BOOL mname = NO;
|
||||
int yd = 0, md = 0, dd = 0, hd = 0, mnd = 0, sd = 0;
|
||||
int nhd;
|
||||
int i, j, k;
|
||||
BOOL mname = NO, dname = NO;
|
||||
double s;
|
||||
int yd = 0, md = 0, dd = 0, mnd = 0, sd = 0, dom = -1, dow = -1, doy = -1;
|
||||
int hd = 0, nhd;
|
||||
int i, j, k, z;
|
||||
|
||||
// If the format is nil then return an empty string
|
||||
if (!format)
|
||||
return @"";
|
||||
|
||||
[self getYear: &yd month: &md day: &dd hour: &hd minute: &mnd second: &sd];
|
||||
[self getYear: &yd month: &md day: &dom hour: &hd minute: &mnd second: &sd];
|
||||
nhd = hd;
|
||||
|
||||
// The strftime specifiers
|
||||
|
@ -572,7 +671,9 @@ static id long_month[12] = {@"January",
|
|||
// %A full weekday name according to locale
|
||||
// %b abbreviated month name according to locale
|
||||
// %B full month name according to locale
|
||||
// %d day of month as decimal number
|
||||
// %d day of month as decimal number (leading zero)
|
||||
// %e day of month as decimal number (leading space)
|
||||
// %F milliseconds (000 to 999)
|
||||
// %H hour as a decimal number using 24-hour clock
|
||||
// %I hour as a decimal number using 12-hour clock
|
||||
// %j day of year as a decimal number
|
||||
|
@ -585,6 +686,7 @@ static id long_month[12] = {@"January",
|
|||
// %w day of the week as decimal number (Sunday = 0)
|
||||
// %y year as a decimal number without century
|
||||
// %Y year as a decimal number with century
|
||||
// %z time zone offset (HHMM)
|
||||
// %Z time zone
|
||||
// %% literal % character
|
||||
|
||||
|
@ -638,23 +740,53 @@ static id long_month[12] = {@"January",
|
|||
j += k;
|
||||
break;
|
||||
|
||||
// is it the day
|
||||
case 'd': // day of month
|
||||
++i;
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", dom));
|
||||
j += k;
|
||||
break;
|
||||
|
||||
case 'e': // day of month
|
||||
++i;
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%2d", dom));
|
||||
j += k;
|
||||
break;
|
||||
|
||||
case 'F': // milliseconds
|
||||
s = ([self dayOfCommonEra] - GREGORIAN_REFERENCE) * 86400.0;
|
||||
s -= (seconds_since_ref+[time_zone timeZoneSecondsFromGMT]);
|
||||
s = abs(s);
|
||||
s -= floor(s);
|
||||
++i;
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%03d", (int)s*1000));
|
||||
j += k;
|
||||
break;
|
||||
|
||||
case 'j': // day of year
|
||||
if (doy < 0) doy = [self dayOfYear];
|
||||
++i;
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", doy));
|
||||
j += k;
|
||||
break;
|
||||
|
||||
// is it the week-day
|
||||
case 'a':
|
||||
dname = YES;
|
||||
case 'A':
|
||||
dtag = YES; // Day is character string
|
||||
case 'd':
|
||||
case 'j':
|
||||
case 'w':
|
||||
++i;
|
||||
if (dow < 0) dow = [self dayOfWeek];
|
||||
if (dtag)
|
||||
{
|
||||
// +++ Translate to locale character string
|
||||
/* Was: k = sprintf(&(buf[j]), ""); */
|
||||
buf[j] = '\0';
|
||||
k = 0;
|
||||
if (dname)
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [short_day[dow] cString]));
|
||||
else
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [long_day[dow] cString]));
|
||||
}
|
||||
else
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", dd));
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", dow));
|
||||
j += k;
|
||||
break;
|
||||
|
||||
|
@ -701,6 +833,19 @@ static id long_month[12] = {@"January",
|
|||
j += k;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
++i;
|
||||
z = [time_zone timeZoneSecondsFromGMT];
|
||||
if (z < 0) {
|
||||
z = -z;
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]),"-%02d%02d",z/60,z%60));
|
||||
}
|
||||
else {
|
||||
k = VSPRINTF_LENGTH(sprintf(&(buf[j]),"+%02d%02d",z/60,z%60));
|
||||
}
|
||||
j += k;
|
||||
break;
|
||||
|
||||
// Anything else is unknown so just copy
|
||||
default:
|
||||
buf[j] = f[i];
|
||||
|
@ -815,3 +960,236 @@ static id long_month[12] = {@"January",
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSCalendarDate (OPENSTEP)
|
||||
|
||||
- (NSCalendarDate *)dateByAddingYears:(int)years
|
||||
months:(int)months
|
||||
days:(int)days
|
||||
hours:(int)hours
|
||||
minutes:(int)minutes
|
||||
seconds:(int)seconds
|
||||
{
|
||||
int i, year, month, day, hour, minute, second;
|
||||
|
||||
[self getYear: &year
|
||||
month: &month
|
||||
day: &day
|
||||
hour: &hour
|
||||
minute: &minute
|
||||
second: &second];
|
||||
|
||||
second += seconds;
|
||||
minute += second/60;
|
||||
second %= 60;
|
||||
if (second < 0)
|
||||
{
|
||||
minute--;
|
||||
second += 60;
|
||||
}
|
||||
|
||||
minute += minutes;
|
||||
hour += minute/60;
|
||||
minute %= 60;
|
||||
if (minute < 0)
|
||||
{
|
||||
hour--;
|
||||
minute += 60;
|
||||
}
|
||||
|
||||
hour += hours;
|
||||
day += hour/24;
|
||||
hour %= 24;
|
||||
if (hour < 0)
|
||||
{
|
||||
day--;
|
||||
hour += 24;
|
||||
}
|
||||
|
||||
day += days;
|
||||
if (day > 0)
|
||||
{
|
||||
i = [self lastDayOfGregorianMonth: month year: year];
|
||||
while (day > i)
|
||||
{
|
||||
day -= i;
|
||||
if (month < 12)
|
||||
month++;
|
||||
else
|
||||
{
|
||||
month = 0;
|
||||
year++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
while (day < 0)
|
||||
{
|
||||
if (month == 1)
|
||||
{
|
||||
year--;
|
||||
month = 12;
|
||||
}
|
||||
else
|
||||
month--;
|
||||
day += [self lastDayOfGregorianMonth: month year: year];
|
||||
}
|
||||
|
||||
month += months;
|
||||
while (month > 12)
|
||||
{
|
||||
year++;
|
||||
month -= 12;
|
||||
}
|
||||
while (month < 1)
|
||||
{
|
||||
year--;
|
||||
month += 12;
|
||||
}
|
||||
|
||||
year += years;
|
||||
|
||||
return [NSCalendarDate dateWithYear:year
|
||||
month:month
|
||||
day:day
|
||||
hour:hour
|
||||
minute:minute
|
||||
second:second
|
||||
timeZone:nil];
|
||||
}
|
||||
|
||||
- (void) years: (int*)years
|
||||
months: (int*)months
|
||||
days: (int*)days
|
||||
hours: (int*)hours
|
||||
minutes: (int*)minutes
|
||||
seconds: (int*)seconds
|
||||
sinceDate: (NSDate*)date
|
||||
{
|
||||
NSCalendarDate *start;
|
||||
NSCalendarDate *end;
|
||||
NSCalendarDate *tmp;
|
||||
int diff;
|
||||
int extra;
|
||||
int sign;
|
||||
int syear, smonth, sday, shour, sminute, ssecond;
|
||||
int eyear, emonth, eday, ehour, eminute, esecond;
|
||||
|
||||
/* FIXME What if the two dates are in different time zones?
|
||||
How about daylight savings time?
|
||||
*/
|
||||
if ([date isKindOfClass: [NSCalendarDate class]])
|
||||
tmp = (NSCalendarDate*)[date retain];
|
||||
else
|
||||
tmp = [[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
|
||||
[date timeIntervalSinceReferenceDate]];
|
||||
|
||||
end = (NSCalendarDate*)[self laterDate: tmp];
|
||||
if (end == self)
|
||||
{
|
||||
start = tmp;
|
||||
sign = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = self;
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
[start getYear: &syear
|
||||
month: &smonth
|
||||
day: &sday
|
||||
hour: &shour
|
||||
minute: &sminute
|
||||
second: &ssecond];
|
||||
[end getYear: &eyear
|
||||
month: &emonth
|
||||
day: &eday
|
||||
hour: &ehour
|
||||
minute: &eminute
|
||||
second: &esecond];
|
||||
|
||||
/* Calculate year difference and leave any remaining months in 'extra' */
|
||||
diff = eyear - syear;
|
||||
extra = 0;
|
||||
if (emonth < smonth)
|
||||
{
|
||||
diff--;
|
||||
extra += 12;
|
||||
}
|
||||
if (years)
|
||||
*years = sign*diff;
|
||||
else
|
||||
extra += diff*12;
|
||||
|
||||
/* Calculate month difference and leave any remaining days in 'extra' */
|
||||
diff = emonth - smonth + extra;
|
||||
extra = 0;
|
||||
if (eday < sday)
|
||||
{
|
||||
diff--;
|
||||
if (emonth > 1)
|
||||
extra = [end lastDayOfGregorianMonth: emonth-1 year: eyear];
|
||||
else
|
||||
extra = 31;
|
||||
}
|
||||
if (months)
|
||||
*months = sign*diff;
|
||||
else
|
||||
{
|
||||
while (diff--) {
|
||||
if (emonth - diff >= 1)
|
||||
extra += [end lastDayOfGregorianMonth: emonth-diff year: eyear];
|
||||
else
|
||||
extra += [end lastDayOfGregorianMonth: emonth-diff+12 year: eyear-1];
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate day difference and leave any remaining hours in 'extra' */
|
||||
diff = eday - sday + extra;
|
||||
extra = 0;
|
||||
if (ehour < shour)
|
||||
{
|
||||
diff--;
|
||||
extra = 24;
|
||||
}
|
||||
if (days)
|
||||
*days = sign*diff;
|
||||
else
|
||||
extra += diff*24;
|
||||
|
||||
/* Calculate hour difference and leave any remaining minutes in 'extra' */
|
||||
diff = ehour - shour + extra;
|
||||
extra = 0;
|
||||
if (eminute < sminute)
|
||||
{
|
||||
diff--;
|
||||
extra = 60;
|
||||
}
|
||||
if (hours)
|
||||
*hours = sign*diff;
|
||||
else
|
||||
extra += diff*60;
|
||||
|
||||
/* Calculate minute difference and leave any remaining seconds in 'extra' */
|
||||
diff = eminute - sminute + extra;
|
||||
extra = 0;
|
||||
if (esecond < ssecond)
|
||||
{
|
||||
diff--;
|
||||
extra = 60;
|
||||
}
|
||||
if (minutes)
|
||||
*minutes = sign*diff;
|
||||
else
|
||||
extra += diff*60;
|
||||
|
||||
diff = esecond - ssecond + extra;
|
||||
if (seconds)
|
||||
*seconds = sign*diff;
|
||||
|
||||
[tmp release];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -81,7 +81,8 @@
|
|||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
#define VM_ACCESS 0644 /* self read/write - other readonly */
|
||||
#define VM_RDONLY 0644 /* self read/write - other readonly */
|
||||
#define VM_ACCESS 0666 /* read/write access for all */
|
||||
@class NSDataShared;
|
||||
@class NSMutableDataShared;
|
||||
#endif
|
||||
|
@ -1334,7 +1335,18 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
{
|
||||
if (bytes)
|
||||
{
|
||||
shmdt(bytes);
|
||||
struct shmid_ds buf;
|
||||
|
||||
if (shmctl(shmid, IPC_STAT, &buf) < 0)
|
||||
NSLog(@"[NSDataShared -dealloc] shared memory control failed - %s",
|
||||
strerror(errno));
|
||||
else if (buf.shm_nattch == 1)
|
||||
if (shmctl(shmid, IPC_RMID, &buf) < 0) /* Mark for deletion. */
|
||||
NSLog(@"[NSDataShared -dealloc] shared memory delete failed - %s",
|
||||
strerror(errno));
|
||||
if (shmdt(bytes) < 0)
|
||||
NSLog(@"[NSDataShared -dealloc] shared memory detach failed - %s",
|
||||
strerror(errno));
|
||||
bytes = 0;
|
||||
length = 0;
|
||||
shmid = -1;
|
||||
|
@ -1352,7 +1364,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
shmid = -1;
|
||||
if (aBuffer && bufferSize)
|
||||
{
|
||||
shmid = shmget(IPC_PRIVATE, bufferSize, IPC_CREAT|VM_ACCESS);
|
||||
shmid = shmget(IPC_PRIVATE, bufferSize, IPC_CREAT|VM_RDONLY);
|
||||
if (shmid == -1) /* Created memory? */
|
||||
{
|
||||
NSLog(@"[-initWithBytes:length:] shared mem get failed for %u - %s",
|
||||
|
@ -1363,7 +1375,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
}
|
||||
|
||||
bytes = shmat(shmid, 0, 0);
|
||||
shmctl(shmid, IPC_RMID, &buf); /* Mark for later deletion. */
|
||||
if (bytes == (void*)-1)
|
||||
{
|
||||
NSLog(@"[-initWithBytes:length:] shared mem attach failed for %u - %s",
|
||||
|
@ -1670,7 +1681,15 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
{
|
||||
if (bytes)
|
||||
{
|
||||
shmdt(bytes);
|
||||
struct shmid_ds buf;
|
||||
|
||||
if (shmctl(shmid, IPC_STAT, &buf) < 0)
|
||||
NSLog(@"[NSMutableDataShared -dealloc] shared memory control failed - %s", strerror(errno));
|
||||
else if (buf.shm_nattch == 1)
|
||||
if (shmctl(shmid, IPC_RMID, &buf) < 0) /* Mark for deletion. */
|
||||
NSLog(@"[NSMutableDataShared -dealloc] shared memory delete failed - %s", strerror(errno));
|
||||
if (shmdt(bytes) < 0)
|
||||
NSLog(@"[NSMutableDataShared -dealloc] shared memory detach failed - %s", strerror(errno));
|
||||
bytes = 0;
|
||||
length = 0;
|
||||
capacity = 0;
|
||||
|
@ -1710,8 +1729,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
|
||||
bytes = shmat(shmid, 0, 0);
|
||||
e = errno;
|
||||
shmctl(shmid, IPC_RMID, &buf); /* Mark for later deletion. */
|
||||
|
||||
if (bytes == (void*)-1)
|
||||
{
|
||||
NSLog(@"[NSMutableDataShared -initWithCapacity:] shared memory attach failed for %u - %s", bufferSize, strerror(e));
|
||||
|
@ -1774,13 +1791,22 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
format:@"Unable to create shared memory segment - %s.",
|
||||
strerror(errno)];
|
||||
tmp = shmat(newid, 0, 0);
|
||||
if (shmctl(newid, IPC_RMID, &buf) == 0) /* Mark for later deletion. */
|
||||
if ((int)tmp == -1) /* Attached memory? */
|
||||
[NSException raise:NSMallocException
|
||||
format:@"Unable to attach to shared memory segment."];
|
||||
memcpy(tmp, bytes, length);
|
||||
if (bytes)
|
||||
shmdt(bytes);
|
||||
{
|
||||
struct shmid_ds buf;
|
||||
|
||||
if (shmctl(shmid, IPC_STAT, &buf) < 0)
|
||||
NSLog(@"[NSMutableDataShared -setCapacity:] shared memory control failed - %s", strerror(errno));
|
||||
else if (buf.shm_nattch == 1)
|
||||
if (shmctl(shmid, IPC_RMID, &buf) < 0) /* Mark for deletion. */
|
||||
NSLog(@"[NSMutableDataShared -setCapacity:] shared memory delete failed - %s", strerror(errno));
|
||||
if (shmdt(bytes) < 0) /* Detach memory. */
|
||||
NSLog(@"[NSMutableDataShared -setCapacity:] shared memory detach failed - %s", strerror(errno));
|
||||
}
|
||||
bytes = tmp;
|
||||
shmid = newid;
|
||||
capacity = size;
|
||||
|
|
|
@ -320,7 +320,7 @@ extraRefCount (id anObject)
|
|||
if (double_release_check_enabled)
|
||||
{
|
||||
unsigned release_count;
|
||||
unsigned retain_count = extraRefCount(self);
|
||||
unsigned retain_count = [self retainCount];
|
||||
release_count = [autorelease_class autoreleaseCountForObject:self];
|
||||
if (release_count > retain_count)
|
||||
[NSException
|
||||
|
@ -421,9 +421,9 @@ extraRefCount (id anObject)
|
|||
if (double_release_check_enabled)
|
||||
{
|
||||
unsigned release_count;
|
||||
unsigned retain_count = extraRefCount(self);
|
||||
unsigned retain_count = [self retainCount];
|
||||
release_count = [autorelease_class autoreleaseCountForObject:self];
|
||||
if (release_count > retain_count)
|
||||
if (release_count >= retain_count)
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Release would release object too many times."];
|
||||
}
|
||||
|
@ -458,11 +458,7 @@ extraRefCount (id anObject)
|
|||
|
||||
- (unsigned) retainCount
|
||||
{
|
||||
unsigned release_count;
|
||||
unsigned retain_count = extraRefCount(self) + 1;
|
||||
release_count = [autorelease_class autoreleaseCountForObject:self];
|
||||
|
||||
return retain_count - release_count;
|
||||
return extraRefCount(self) + 1;
|
||||
}
|
||||
|
||||
+ (unsigned) retainCount
|
||||
|
|
|
@ -39,9 +39,6 @@
|
|||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSProxy* ob = (NSProxy*) NSAllocateObject (self, 0, z);
|
||||
if (ob) {
|
||||
[ob retain];
|
||||
}
|
||||
return ob;
|
||||
}
|
||||
|
||||
|
@ -217,7 +214,7 @@
|
|||
|
||||
- (void) release
|
||||
{
|
||||
if (_retain_count-- == 1) {
|
||||
if (_retain_count-- == 0) {
|
||||
[self dealloc];
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +244,12 @@
|
|||
|
||||
- (unsigned int) retainCount
|
||||
{
|
||||
return _retain_count;
|
||||
return _retain_count + 1;
|
||||
}
|
||||
|
||||
+ (unsigned) retainCount
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
- self
|
||||
|
|
|
@ -1110,11 +1110,12 @@ static int debug_run_loop = 0;
|
|||
}
|
||||
|
||||
/* Use the earlier of the two dates we have. */
|
||||
d = [d earlierDate:date];
|
||||
d = [[d earlierDate:date] retain];
|
||||
|
||||
/* Wait, listening to our input sources. */
|
||||
[self acceptInputForMode: mode beforeDate: d];
|
||||
|
||||
[d release];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,13 +85,13 @@
|
|||
|
||||
- (oneway void) release
|
||||
{
|
||||
if (!_retain_count--)
|
||||
if (_retain_count-- == 0)
|
||||
[self dealloc];
|
||||
}
|
||||
|
||||
- (unsigned) retainCount
|
||||
{
|
||||
return _retain_count;
|
||||
return _retain_count + 1;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
|
|
@ -462,7 +462,7 @@ enum
|
|||
|
||||
- (unsigned) retainCount
|
||||
{
|
||||
return _retain_count;
|
||||
return _retain_count + 1;
|
||||
}
|
||||
|
||||
- autorelease
|
||||
|
|
|
@ -63,8 +63,8 @@
|
|||
|
||||
#define GDOMAP 1 /* 1 = Use name server. */
|
||||
#define stringify_it(X) #X
|
||||
#define make_gdomap_cmd(X) stringify_it(X) "/bin/gdomap &"
|
||||
#define make_gdomap_err(X) "check that " stringify_it(X) "/bin/gdomap is running and owned by root."
|
||||
#define make_gdomap_cmd(X) stringify_it(X) "/Tools/gdomap &"
|
||||
#define make_gdomap_err(X) "check that " stringify_it(X) "/Tools/gdomap is running and owned by root."
|
||||
|
||||
#endif /* !__WIN32__ */
|
||||
#include <string.h> /* for memset() and strchr() */
|
||||
|
@ -145,7 +145,7 @@ static int debug_tcp_port = 0;
|
|||
/*
|
||||
* Code to contact distributed objects name server.
|
||||
*/
|
||||
#include "gdomap.h"
|
||||
#include "../Tools/gdomap.h"
|
||||
|
||||
extern int errno; /* For systems where it is not in the include */
|
||||
|
||||
|
|
|
@ -63,7 +63,8 @@
|
|||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
# after-distclean::
|
||||
after-distclean::
|
||||
rm -f cstream.dat fref.dat nsarchiver.dat
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
ADDITIONAL_CPPFLAGS =
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
ADDITIONAL_OBJCFLAGS =
|
||||
ADDITIONAL_OBJCFLAGS = -g
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
ADDITIONAL_CFLAGS =
|
||||
|
|
|
@ -85,6 +85,9 @@ main()
|
|||
c = [NSCalendarDate calendarDate];
|
||||
printf("+[calendarDate] -- %s\n", [[c description] cString]);
|
||||
printf("-[dayOfMonth] %d\n", [c dayOfMonth]);
|
||||
printf("-[dayOfWeek] %d\n", [c dayOfWeek]);
|
||||
printf("-[dayOfYear] %d\n", [c dayOfYear]);
|
||||
printf("-[hourOfDay] %d\n", [c hourOfDay]);
|
||||
printf("-[monthOfYear] %d\n", [c monthOfYear]);
|
||||
printf("-[yearOfCommonEra] %d\n", [c yearOfCommonEra]);
|
||||
|
||||
|
@ -118,6 +121,23 @@ main()
|
|||
printf("calendar date %s\n", [[e description] cString]);
|
||||
printf("-[timeIntervalSinceReferenceDate] %f\n",
|
||||
[e timeIntervalSinceReferenceDate]);
|
||||
printf("NSCalendrical time tests\n");
|
||||
{
|
||||
NSCalendarDate *momsBDay = [NSCalendarDate dateWithYear:1936
|
||||
month:1 day:8 hour:7 minute:30 second:0
|
||||
timeZone:[NSTimeZone timeZoneWithName:@"EST"]];
|
||||
NSCalendarDate *dob = [NSCalendarDate dateWithYear:1965
|
||||
month:12 day:7 hour:17 minute:25 second:0
|
||||
timeZone:[NSTimeZone timeZoneWithName:@"EST"]];
|
||||
int years, months, days;
|
||||
|
||||
[dob years:&years months:&months days:&days hours:0
|
||||
minutes:0 seconds:0 sinceDate:momsBDay];
|
||||
printf("%d, %d, %d\n", years, months, days);
|
||||
[dob years:0 months:&months days:&days hours:0
|
||||
minutes:0 seconds:0 sinceDate:momsBDay];
|
||||
printf("%d, %d\n", months, days);
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
|
13
Tools/Makefile
Normal file
13
Tools/Makefile
Normal file
|
@ -0,0 +1,13 @@
|
|||
include $(GNUSTEP_SYSTEM_ROOT)/Makefiles/common.make
|
||||
|
||||
# The application to be compiled
|
||||
TOOL_NAME = gdomap
|
||||
|
||||
# The source files to be compiled
|
||||
gdomap_C_FILES = gdomap.c
|
||||
|
||||
-include Makefile.preamble
|
||||
|
||||
include $(GNUSTEP_SYSTEM_ROOT)/Makefiles/tool.make
|
||||
|
||||
-include Makefile.postamble
|
46
Tools/Makefile.postamble
Normal file
46
Tools/Makefile.postamble
Normal file
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# Makefile.postamble
|
||||
#
|
||||
# Project specific makefile rules
|
||||
#
|
||||
# Uncomment the targets you want.
|
||||
# The double colons (::) are important, do not make them single colons
|
||||
# otherwise the normal makefile rules will not be performed.
|
||||
#
|
||||
|
||||
# Things to do before compiling
|
||||
# before-all::
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
before-install::
|
||||
$(INSTALL) -m 05755 gdomap $(GNUSTEP_SYSTEM_ROOT)/Tools
|
||||
|
||||
# Things to do after installing
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
# after-distclean::
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
43
Tools/Makefile.preamble
Normal file
43
Tools/Makefile.preamble
Normal file
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# Makefile.preamble
|
||||
#
|
||||
# Project specific makefile variables, and additional
|
||||
#
|
||||
# Do not put any Makefile rules in this file, instead they should
|
||||
# be put into Makefile.postamble.
|
||||
#
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
ADDITIONAL_CPPFLAGS +=
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
ADDITIONAL_OBJCFLAGS +=
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
ADDITIONAL_CFLAGS +=
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS +=
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
# ADDITIONAL_LDFLAGS +=
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS +=
|
||||
|
||||
# Additional libraries when linking tools
|
||||
ADDITIONAL_TOOL_LIBS +=
|
||||
|
||||
# Additional libraries when linking applications
|
||||
ADDITIONAL_GUI_LIBS +=
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
# Additional directories to be created during installation
|
||||
ADDITIONAL_INSTALL_DIRS +=
|
|
@ -255,8 +255,9 @@ unsigned short next_port = IPPORT_USERRESERVED;
|
|||
typedef struct {
|
||||
unsigned char* name; /* Service name registered. */
|
||||
unsigned int port; /* Port it was mapped to. */
|
||||
unsigned char size; /* Number of bytes in name. */
|
||||
unsigned char type; /* Type of port registered. */
|
||||
unsigned short size; /* Number of bytes in name. */
|
||||
unsigned char net; /* Type of port registered. */
|
||||
unsigned char svc; /* Type of port registered. */
|
||||
} map_ent;
|
||||
|
||||
int map_used = 0;
|
||||
|
@ -289,7 +290,8 @@ map_add(unsigned char* n, unsigned char l, unsigned int p, unsigned char t)
|
|||
m->port = p;
|
||||
m->name = (char*)malloc(l);
|
||||
m->size = l;
|
||||
m->type = t;
|
||||
m->net = (t & GDO_NET_MASK);
|
||||
m->svc = (t & GDO_SVC_MASK);
|
||||
mcopy(m->name, n, l);
|
||||
|
||||
if (map_used >= map_size) {
|
||||
|
@ -839,8 +841,8 @@ handle_accept()
|
|||
mcopy((char*)&r_info[desc].addr, (char*)&sa, sizeof(sa));
|
||||
|
||||
if (debug) {
|
||||
fprintf(stderr, "accept from %s to chan %d\n",
|
||||
inet_ntoa(sa.sin_addr), desc);
|
||||
fprintf(stderr, "accept from %s(%d) to chan %d\n",
|
||||
inet_ntoa(sa.sin_addr), ntohs(sa.sin_port), desc);
|
||||
}
|
||||
/*
|
||||
* Ensure that the connection is non-blocking.
|
||||
|
@ -1044,11 +1046,12 @@ handle_request(int desc)
|
|||
|
||||
if (debug > 1) {
|
||||
if (desc == udp_desc) {
|
||||
fprintf(stderr, "request type '%c' on UDP chan\n", type);
|
||||
fprintf(stderr, "request type '%c' on UDP chan", type);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "request type '%c' from chan %d\n", type, desc);
|
||||
fprintf(stderr, "request type '%c' from chan %d", type, desc);
|
||||
}
|
||||
fprintf(stderr, " - name: '%.*s' port: %d\n", size, buf, port);
|
||||
}
|
||||
|
||||
if (ptype != GDO_TCP_GDO && ptype != GDO_TCP_FOREIGN &&
|
||||
|
@ -1083,37 +1086,38 @@ handle_request(int desc)
|
|||
clear_chan(desc); /* Only local progs may register. */
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* What should we do if we already have the name registered?
|
||||
* Simple algorithm -
|
||||
* We check to see if we can bind to the old port,
|
||||
* and if we can we assume that the original process
|
||||
* has gone away and permit a new registration for the
|
||||
* same name.
|
||||
* This is not foolproof - if the machine has more
|
||||
* than one IP address, we could bind to the port on
|
||||
* one address even though the server is using it on
|
||||
* another.
|
||||
* Also - the operating system is not guaranteed to
|
||||
* let us bind to the port if another process has only
|
||||
* recently stopped using it.
|
||||
* Also - what if an old server used the port that the
|
||||
* new one is using? In this case the registration
|
||||
* attempt will be refused even though it shouldn't be!
|
||||
* On the other hand - the occasional registration
|
||||
* failure MUST be better than permitting a process to
|
||||
* grab a name already in use! If a server fails to
|
||||
* register a name/port combination, it can always be
|
||||
* coded to retry on a different port.
|
||||
*/
|
||||
m = map_by_name(buf, size);
|
||||
if (m) {
|
||||
int sock = -1;
|
||||
|
||||
/*
|
||||
* What should we do here?
|
||||
* Simple algorithm -
|
||||
* We check to see if we can bind to the old port,
|
||||
* and if we can we assume that the original process
|
||||
* has gone away and permit a new registration for the
|
||||
* same name.
|
||||
* This is not foolproof - if the machine has more
|
||||
* than one IP address, we could bind to the port on
|
||||
* one address even though the server is using it on
|
||||
* another.
|
||||
* Also - the operating system is not guaranteed to
|
||||
* let us bind to the port if another process has only
|
||||
* recently stopped using it.
|
||||
* Also - what if an old server used the port that the
|
||||
* new one is using? In this case the registration
|
||||
* attempt will be refused even though it shouldn't be!
|
||||
* On the other hand - the occasional registration
|
||||
* failure MUST be better than permitting a process to
|
||||
* grab a name already in use! If a server fails to
|
||||
* register a name/port combination, it can always be
|
||||
* coded to retry on a different port.
|
||||
*/
|
||||
if (ptype == GDO_TCP_GDO || ptype == GDO_TCP_FOREIGN) {
|
||||
if ((ptype & GDO_NET_MASK) == GDO_NET_TCP) {
|
||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
else if (ptype == GDO_UDP_GDO || ptype == GDO_UDP_FOREIGN) {
|
||||
else if ((ptype & GDO_NET_MASK) == GDO_NET_UDP) {
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
}
|
||||
|
||||
|
@ -1129,7 +1133,7 @@ handle_request(int desc)
|
|||
else {
|
||||
struct sockaddr_in sa;
|
||||
int result;
|
||||
short p = m->port;
|
||||
short p = m->port;
|
||||
|
||||
mzero(&sa, sizeof(sa));
|
||||
sa.sin_family = AF_INET;
|
||||
|
@ -1138,10 +1142,12 @@ handle_request(int desc)
|
|||
result = bind(sock, (void*)&sa, sizeof(sa));
|
||||
if (result == 0) {
|
||||
if (debug > 1) {
|
||||
fprintf(stderr, "re-register name from %d to %d\n",
|
||||
fprintf(stderr, "re-register from %d to %d\n",
|
||||
m->port, port);
|
||||
}
|
||||
m->port = port;
|
||||
m->net = (ptype & GDO_NET_MASK);
|
||||
m->svc = (ptype & GDO_SVC_MASK);
|
||||
port = htonl(m->port);
|
||||
*(unsigned long*)w_info[desc].buf = port;
|
||||
}
|
||||
|
@ -1149,7 +1155,7 @@ handle_request(int desc)
|
|||
close(sock);
|
||||
}
|
||||
}
|
||||
else if (port == 0) { /* Port not provided in request. */
|
||||
else if (port == 0) { /* Port not provided! */
|
||||
fprintf(stderr, "port not provided in request\n");
|
||||
}
|
||||
else { /* Use port provided in request. */
|
||||
|
@ -1160,11 +1166,11 @@ handle_request(int desc)
|
|||
}
|
||||
else if (type == GDO_LOOKUP) {
|
||||
m = map_by_name(buf, size);
|
||||
if (m != 0 && m->type != ptype) {
|
||||
if (m != 0 && (m->net | m->svc) != ptype) {
|
||||
if (debug > 1) {
|
||||
fprintf(stderr, "requested service is of wrong type\n");
|
||||
}
|
||||
m = 0; /* Name existas but is of wrong type. */
|
||||
m = 0; /* Name exists but is of wrong type. */
|
||||
}
|
||||
if (m) {
|
||||
int sock = -1;
|
||||
|
@ -1178,10 +1184,10 @@ handle_request(int desc)
|
|||
* one address even though the server is using it on
|
||||
* another.
|
||||
*/
|
||||
if (ptype == GDO_TCP_GDO || ptype == GDO_TCP_FOREIGN) {
|
||||
if ((ptype & GDO_NET_MASK) == GDO_NET_TCP) {
|
||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
else if (ptype == GDO_UDP_GDO || ptype == GDO_UDP_FOREIGN) {
|
||||
else if ((ptype & GDO_NET_MASK) == GDO_NET_UDP) {
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
}
|
||||
|
||||
|
@ -1233,20 +1239,15 @@ handle_request(int desc)
|
|||
}
|
||||
m = map_by_name(buf, size);
|
||||
if (m) {
|
||||
if (m->type != ptype) {
|
||||
if ((m->net | m->svc) != ptype) {
|
||||
if (debug) {
|
||||
fprintf(stderr, "Attempt to unregister with wrong type\n");
|
||||
}
|
||||
}
|
||||
else if (r_info[desc].addr.sin_port == m->port) {
|
||||
else {
|
||||
*(unsigned long*)w_info[desc].buf = htonl(m->port);
|
||||
map_del(m);
|
||||
}
|
||||
else {
|
||||
if (debug) {
|
||||
fprintf(stderr, "Illegal attempt to un-register!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (debug > 1) {
|
|
@ -32,7 +32,7 @@
|
|||
* The communications protocol is identical for both TCP and UDP and
|
||||
* consists of a simple request-response sequence.
|
||||
*
|
||||
* Each request is a single 264 byte message consisting of -
|
||||
* Each request is a single message consisting of -
|
||||
* a single byte request type,
|
||||
* a single byte giving name length,
|
||||
* a single byte specifying the type of port being registered
|
||||
|
@ -40,13 +40,13 @@
|
|||
* a single nul byte.
|
||||
* a four byte port number in network byte order must be
|
||||
* present for register operations, otherwise this is zero.
|
||||
* a service name of 0 to 255 bytes (or an IP address in
|
||||
* network byte order for probe operations)
|
||||
* 0 to 254 nul bytes padding the service name to 255.
|
||||
* a service name of 0 to GDO_NAME_MAX_LEN bytes (or an IP
|
||||
* address in network byte order for probe operations)
|
||||
* 0 to GDO_NAME_MAX_LEN nul bytes padding the service name to its
|
||||
* full size.
|
||||
* a terminating nul byte.
|
||||
* The total is always sent in a packet of 262 bytes with
|
||||
* everything after the service name (except the final byte)
|
||||
* cleared to nul bytes.
|
||||
* The total is always sent in a packet with everything after the
|
||||
* service name (except the final byte) cleared to nul bytes.
|
||||
*
|
||||
* Each response consists of at least 4 bytes and depends on the
|
||||
* corresponding request type and where it came from as follows -
|
||||
|
@ -65,8 +65,7 @@
|
|||
*
|
||||
* GDO_UNREG Un-register the server name and return old port number.
|
||||
* This service is only available to a process on the
|
||||
* same host as this name server and which sent the
|
||||
* request from the port associated with the name.
|
||||
* same host as this name server.
|
||||
* Response is the old port number in network byte order,
|
||||
* or zero if the name could not be un-registered.
|
||||
*
|
||||
|
@ -136,6 +135,14 @@
|
|||
* Things are never perfect though - if a name server dies, the
|
||||
* other name servers won't know, and will continute to tell
|
||||
* applications that it is there.
|
||||
*
|
||||
* 3. Port type codes - these are used to say what the port is for so
|
||||
* that clients can look up only the names that are relevant to them.
|
||||
* This is to permit the name server to be used for multiple
|
||||
* communications protocols (at the moment, tcp or udp) and for
|
||||
* different systems (distributed objects or others).
|
||||
* This guarantees that if one app is using DO over UDP, its services
|
||||
* will not be found by an app which is using DO over TCP.
|
||||
*/
|
||||
|
||||
#define GDOMAP_PORT (538) /* The well-known port for name server. */
|
||||
|
@ -153,22 +160,39 @@
|
|||
/*
|
||||
* Port type codes
|
||||
*/
|
||||
#define GDO_TCP_GDO 'T' /* tcp/ip distributed object server. */
|
||||
#define GDO_UDP_GDO 'U' /* udp/ip distributed object server. */
|
||||
#define GDO_TCP_FOREIGN 't' /* tcp/ip simple socket connection. */
|
||||
#define GDO_UDP_FOREIGN 'u' /* udp/ip simple socket connection. */
|
||||
#define GDO_NET_MASK 0x70 /* Network protocol of port. */
|
||||
#define GDO_NET_TCP 0x10
|
||||
#define GDO_NET_UDP 0x10
|
||||
#define GDO_SVC_MASK 0x0f /* High level protocol of port. */
|
||||
#define GDO_SVC_GDO 0x01
|
||||
#define GDO_SVC_FOREIGN 0x02
|
||||
|
||||
/* tcp/ip distributed object server. */
|
||||
#define GDO_TCP_GDO (GDO_NET_TCP|GDO_SVC_GDO)
|
||||
|
||||
/* udp/ip distributed object server. */
|
||||
#define GDO_UDP_GDO (GDO_NET_UDP|GDO_SVC_GDO)
|
||||
|
||||
/* tcp/ip simple socket connection. */
|
||||
#define GDO_TCP_FOREIGN (GDO_NET_TCP|GDO_SVC_FOREIGN)
|
||||
|
||||
/* udp/ip simple socket connection. */
|
||||
#define GDO_UDP_FOREIGN (GDO_NET_UDP|GDO_SVC_FOREIGN)
|
||||
|
||||
|
||||
#define GDO_NAME_MAX_LEN 255 /* Max length registered name. */
|
||||
|
||||
/*
|
||||
* Structure to hold a request.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned char rtype;
|
||||
unsigned char nsize;
|
||||
unsigned char ptype;
|
||||
unsigned char rtype; /* Type of request being made. */
|
||||
unsigned char nsize; /* Length of the name to use. */
|
||||
unsigned char ptype; /* Type of port registered. */
|
||||
unsigned char dummy;
|
||||
unsigned int port;
|
||||
char name[256];
|
||||
char name[GDO_NAME_MAX_LEN+1];
|
||||
} gdo_req;
|
||||
|
||||
#define GDO_REQ_SIZE 264 /* The size of a request packet. */
|
||||
#define GDO_REQ_SIZE sizeof(gdo_req) /* Size of a request packet. */
|
||||
|
Loading…
Reference in a new issue