Changeset 853
- Timestamp:
- 10/10/08 20:56:40 (2 months ago)
- Files:
-
- trunk/phobos/etc/gamma.d (modified) (15 diffs)
- trunk/phobos/gcstats.d (deleted)
- trunk/phobos/internal (deleted)
- trunk/phobos/linux.mak (modified) (7 diffs)
- trunk/phobos/object.d (deleted)
- trunk/phobos/std/array.d (deleted)
- trunk/phobos/std/asserterror.d (deleted)
- trunk/phobos/std/c/stdio.d (modified) (1 diff)
- trunk/phobos/std/encoding.d (modified) (2 diffs)
- trunk/phobos/std/file.d (modified) (4 diffs)
- trunk/phobos/std/gc.d (deleted)
- trunk/phobos/std/hiddenfunc.d (deleted)
- trunk/phobos/std/md5.d (modified) (1 diff)
- trunk/phobos/std/moduleinit.d (deleted)
- trunk/phobos/std/outbuffer.d (modified) (2 diffs)
- trunk/phobos/std/outofmemory.d (deleted)
- trunk/phobos/std/path.d (modified) (2 diffs)
- trunk/phobos/std/random.d (modified) (17 diffs)
- trunk/phobos/std/signals.d (modified) (7 diffs)
- trunk/phobos/std/socket.d (modified) (107 diffs)
- trunk/phobos/std/stdio.d (modified) (6 diffs)
- trunk/phobos/std/string.d (modified) (4 diffs)
- trunk/phobos/std/switcherr.d (deleted)
- trunk/phobos/std/synchro.d (deleted)
- trunk/phobos/std/thread.d (deleted)
- trunk/phobos/std/typeinfo (deleted)
- trunk/phobos/std/variant.d (modified) (1 diff)
- trunk/phobos/unittest.d (modified) (4 diffs)
- trunk/phobos/win32.mak (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/etc/gamma.d
r697 r853 184 184 * interval (2,3). Large arguments are handled by Stirling's 185 185 * formula. Large negative arguments are made positive using 186 * a reflection formula. 187 */ 186 * a reflection formula. 187 */ 188 188 189 189 real q, z; … … 197 197 if (x == 0) 198 198 return 1.0 / x; // +- infinity depending on sign of x, create an exception. 199 199 200 200 q = fabs(x); 201 201 202 202 if ( q > 13.0L ) 203 203 { 204 204 // Large arguments are handled by Stirling's 205 205 // formula. Large negative arguments are made positive using 206 // the reflection formula. 206 // the reflection formula. 207 207 208 208 if ( x < 0.0L ) … … 230 230 return gammaStirling(x); 231 231 } 232 232 233 233 // Arguments |x| <= 13 are reduced by recurrence and the function 234 234 // approximated by a rational function of degree 7/8 in the … … 241 241 z *= x; 242 242 } 243 243 244 244 while ( x < -0.03125L ) 245 245 { … … 247 247 x += 1.0L; 248 248 } 249 249 250 250 if ( x <= 0.03125L ) 251 251 { … … 262 262 } 263 263 } 264 264 265 265 while ( x < 2.0L ) 266 266 { … … 270 270 if ( x == 2.0L ) 271 271 return z; 272 272 273 273 x -= 2.0L; 274 274 return z * poly( x, GammaNumeratorCoeffs ) / poly( x, GammaDenominatorCoeffs ); … … 315 315 * <tr> <td> ±∞ <td> +∞ <td> no 316 316 * </table> 317 * 317 * 318 318 */ 319 319 real lgamma(real x) … … 330 330 */ 331 331 real q, w, z, f, nx; 332 332 333 333 if (isnan(x)) 334 334 return x; 335 335 if (fabs(x) == x.infinity) 336 336 return x.infinity; 337 337 338 338 if ( x < -34.0L ) 339 339 { … … 386 386 q = z / (x * poly( x, GammaSmallCoeffs)); 387 387 return log( fabs(q) ); 388 } 388 } 389 389 z /= nx + f; 390 390 nx += 1.0L; … … 398 398 return ( log(z) + p ); 399 399 } 400 400 401 401 //const real MAXLGM = 1.04848146839019521116e+4928L; 402 402 //if ( x > MAXLGM ) return sgngaml * real.infinity; … … 404 404 /* log( sqrt( 2*pi ) ) */ 405 405 const real LOGSQRT2PI = 0.91893853320467274178L; 406 406 407 407 q = ( x - 0.5L ) * log(x) - x + LOGSQRT2PI; 408 408 if (x > 1.0e10L) return q; … … 415 415 { 416 416 // return true if x is +0.0 417 b itisPosZero(real x)417 bool isPosZero(real x) 418 418 { 419 419 return (x==0) && (signbit(x)==0); … … 426 426 assert(isPosZero(lgamma(1.0L))); 427 427 assert(isPosZero(lgamma(2.0L))); 428 428 429 429 // x, correct loggamma(x), correct d/dx loggamma(x). 430 430 static real[] testpoints = 431 [ 431 [ 432 432 8.0L, 8.525146484375L + 1.48766904143001655310E-5, 2.01564147795560999654E0L, 433 433 8.99993896484375e-1L, 6.6375732421875e-2L + 5.11505711292524166220E-6L, -7.54938684259372234258E-1, … … 481 481 } 482 482 483 483 trunk/phobos/linux.mak
r829 r853 35 35 CFLAGS = 36 36 DFLAGS = 37 LDFLAGS = 37 LDFLAGS = 38 38 else 39 39 OBJDIR = obj/linux 40 40 OBJEXT = o 41 41 LIBEXT = a 42 EXEEXT = 42 EXEEXT = 43 43 CC = gcc 44 44 DMD = dmd … … 91 91 92 92 ifneq (none,$(OBJDIR)) 93 DUMMY := $(shell mkdir --parents $(OBJDIR) $(OBJDIR)/etc/c/zlib \ 94 $(OBJDIR)/internal $(OBJDIR)/internal/gc) 93 DUMMY := $(shell mkdir --parents $(OBJDIR) $(OBJDIR)/etc/c/zlib) 95 94 endif 96 95 … … 139 138 for m in $(STD_MODULES); do echo public import std.$$m\;; done > $@ 140 139 141 INTERNAL_MODULES = aApply aApplyR aaA adi alloca arraycast arraycat \ 142 cast cmath2 deh2 dmain2 invariant llmath memset monitor obj \ 143 object qsort switch trace arrayassign \ 144 arrayfloat arraydouble arrayreal \ 145 arraybyte arrayshort arrayint 146 INTERNAL_CMODULES = complex critical 147 INTERNAL_CMODULES_NOTBUILT = deh 148 INTERNAL_EXTRAFILES = internal/mars.h internal/minit.asm 149 150 INTERNAL_GC_MODULES = gc gcold gcx gcbits gclinux 151 INTERNAL_GC_EXTRAFILES = \ 152 internal/gc/gcstub.d \ 153 internal/gc/win32.d \ 154 internal/gc/testgc.d \ 155 internal/gc/win32.mak \ 156 internal/gc/linux.mak 157 158 STD_MODULES = algorithm array asserterror atomics base64 bigint bind bitarray \ 140 STD_MODULES = algorithm atomics base64 bigint bind bitarray \ 159 141 bitmanip boxer compiler complex contracts conv cover cpuid \ 160 142 cstream ctype date dateparse demangle encoding file format \ 161 functional getopt hiddenfunc intrinsic iterator loader math\162 md5 metastrings mmfile moduleinit numeric openrj outbuffer\163 outofmemory path perf process random regexp signals socket\164 socketstream stdint stdio stream string s witcherr syserror\165 sy nchro system thread traits typecons typetuple uni uri utf\143 functional getopt intrinsic iterator loader math \ 144 md5 metastrings mmfile numeric openrj outbuffer \ 145 path perf process random regexp signals socket \ 146 socketstream stdint stdio stream string syserror \ 147 system traits typecons typetuple uni uri utf \ 166 148 variant xml zip zlib 167 STD_MODULES_NOTBUILT = stdarg gc149 STD_MODULES_NOTBUILT = stdarg 168 150 169 151 STD_C_MODULES = stdarg stdio … … 192 174 ETC_C_MODULES = zlib 193 175 194 SRC = errno.c object.d unittest.d crc32.d 176 SRC = errno.c object.d unittest.d crc32.d 195 177 196 178 SRC_ZLIB = ChangeLog README adler32.c algorithm.txt compress.c crc32.c \ … … 208 190 209 191 SRC_RELEASEZIP = linux.mak win32.mak phoboslicense.txt $(SRC) \ 210 $(SRC_ZLIB) $(INTERNAL_EXTRAFILES) $(INTERNAL_GC_EXTRAFILES) \ 211 $(addprefix internal/,$(addsuffix .c, \ 212 $(INTERNAL_CMODULES_NOTBUILT))) $(addprefix internal/, \ 213 $(addsuffix .c, $(INTERNAL_CMODULES))) $(addprefix internal/, \ 214 $(addsuffix .d, $(INTERNAL_MODULES))) $(addprefix \ 215 internal/gc/, $(addsuffix .d, $(INTERNAL_GC_MODULES))) \ 216 $(addprefix std/, $(addsuffix .d, $(STD_MODULES) \ 192 $(SRC_ZLIB) $(addprefix std/, $(addsuffix .d, $(STD_MODULES) \ 217 193 $(STD_MODULES_NOTBUILT))) $(addprefix std/c/, $(addsuffix .d, \ 218 194 $(STD_C_MODULES) $(STD_C_MODULES_NOTBUILT))) $(addprefix \ … … 220 196 $(STD_C_LINUX_MODULES_NOTBUILT))) $(addprefix std/c/windows/, \ 221 197 $(addsuffix .d, $(STD_C_WINDOWS_MODULES_NOTBUILT))) \ 222 $(addprefix std/typeinfo/, $(addsuffix .d, \ 223 $(TYPEINFO_MODULES))) $(addprefix std/windows/, $(addsuffix \ 198 $(addprefix std/windows/, $(addsuffix \ 224 199 .d, $(STD_WINDOWS_MODULES_NOTBUILT))) $(addprefix etc/, \ 225 200 $(addsuffix .d, $(ETC_MODULES_NOTBUILT))) $(addprefix etc/c/, \ 226 201 $(addsuffix .d, $(ETC_C_MODULES))) 227 202 228 OBJS = errno $(addprefix internal/, $(INTERNAL_MODULES) \ 229 $(INTERNAL_CMODULES)) $(addprefix internal/gc/, \ 230 $(INTERNAL_GC_MODULES)) $(addprefix etc/c/zlib/, \ 231 $(ZLIB_CMODULES)) 203 OBJS = errno 232 204 233 205 OBJS := $(addsuffix .$(OBJEXT),$(addprefix $(OBJDIR)/,$(OBJS))) 234 206 235 SRC2LIB = crc32 gcstats $(addprefix std/, $(STD_MODULES)) $(addprefix \ 236 std/typeinfo/, $(TYPEINFO_MODULES)) $(addprefix std/c/, \ 207 SRC2LIB = crc32 $(addprefix std/, $(STD_MODULES)) $(addprefix std/c/, \ 237 208 $(STD_C_MODULES)) $(addprefix std/c/linux/, $(STD_C_LINUX_MODULES)) \ 238 209 $(addprefix etc/c/, $(ETC_C_MODULES)) … … 275 246 276 247 HEADERDIR = include 277 HEADERS = object.d \ 278 $(addprefix std/,$(addsuffix .d,$(STD_MODULES))) \ 248 HEADERS = $(addprefix std/,$(addsuffix .d,$(STD_MODULES))) \ 279 249 $(addprefix std/,$(addsuffix .d,$(STD_MODULES_NOTBUILT))) \ 280 250 $(addprefix std/c/,$(addsuffix .d,$(STD_C_MODULES))) \ 281 251 $(addprefix std/c/,$(addsuffix .d,$(STD_C_MODULES_NOTBUILT))) \ 282 252 $(addprefix std/c/linux/,$(addsuffix .d,$(STD_C_LINUX_MODULES))) \ 283 $(addprefix std/c/linux/,$(addsuffix .d,$(STD_C_LINUX_MODULES_NOTBUILT))) 253 $(addprefix std/c/linux/,$(addsuffix .d,$(STD_C_LINUX_MODULES_NOTBUILT))) 284 254 285 255 HEADERS := $(addprefix $(HEADERDIR)/,$(HEADERS)) trunk/phobos/std/c/stdio.d
r689 r853 196 196 size_t fread(void *,size_t,size_t,FILE *); /// 197 197 size_t fwrite(in void *,size_t,size_t,FILE *); /// 198 //int printf(in char *,...); ///198 int printf(in char *,...); /// 199 199 int fprintf(FILE *,in char *,...); /// 200 200 int vfprintf(FILE *,in char *,va_list); /// trunk/phobos/std/encoding.d
r693 r853 2074 2074 static void register(string className) 2075 2075 { 2076 auto scheme = cast(EncodingScheme) Object.factory(className);2076 auto scheme = cast(EncodingScheme)ClassInfo.find(className).create(); 2077 2077 if (scheme is null) 2078 2078 throw new EncodingException("Unable to create class "~className); … … 2101 2101 throw new EncodingException("Unrecognized Encoding: "~encodingName); 2102 2102 string className = *p; 2103 auto scheme = cast(EncodingScheme) Object.factory(className);2103 auto scheme = cast(EncodingScheme)ClassInfo.find(className).create(); 2104 2104 if (scheme is null) throw new EncodingException("Unable to create class "~className); 2105 2105 return scheme; trunk/phobos/std/file.d
r840 r853 38 38 module std.file; 39 39 40 private import memory; 40 41 private import std.c.stdio; 41 42 private import std.c.stdlib; … … 43 44 private import std.string; 44 45 private import std.regexp; 45 private import std.gc;46 46 private import std.c.string; 47 47 private import std.traits; … … 132 132 goto err2; 133 133 134 auto buf = std.gc.malloc(size); 135 if (buf) 136 std.gc.hasNoPointers(buf.ptr); 134 auto buf = GC.malloc(size, GC.BlkAttr.NO_SCAN)[0 .. size]; 137 135 138 136 if (ReadFile(h,buf.ptr,size,&numread,null) != 1) … … 955 953 invariant size = statbuf.st_size; 956 954 if (!size) return null; 957 auto buf = std.gc.malloc(size);955 auto buf = GC.malloc(size, GC.BlkAttr.NO_SCAN); 958 956 enforce(buf, "Out of memory"); 959 957 scope(failure) delete buf; 960 std.gc.hasNoPointers(buf.ptr);961 958 962 959 cenforce(std.c.linux.linux.read(fd, buf.ptr, size) == size, name); trunk/phobos/std/md5.d
r689 r853 89 89 import std.string; 90 90 import std.contracts; 91 import std.c.stdio : printf; 91 92 92 93 /*************************************** trunk/phobos/std/outbuffer.d
r689 r853 19 19 private 20 20 { 21 import memory; 21 22 import std.string; 22 import std.gc;23 23 import std.c.stdio; 24 24 import std.c.stdlib; … … 81 81 { 82 82 data.length = (offset + nbytes) * 2; 83 std.gc.hasPointers(data.ptr);83 GC.clrAttr(data.ptr, GC.BlkAttr.NO_SCAN); 84 84 } 85 85 } trunk/phobos/std/path.d
r849 r853 35 35 private import std.c.stdlib; 36 36 private import std.c.linux.linux; 37 private import std.outofmemory;37 private import exception : onOutOfMemoryError; 38 38 } 39 39 … … 1258 1258 if (extra_memory) 1259 1259 std.c.stdlib.free(extra_memory); 1260 _d_OutOfMemory();1260 onOutOfMemoryError(); 1261 1261 return null; 1262 1262 } trunk/phobos/std/random.d
r846 r853 20 20 Random) for whichever generator it finds the most fit for the target 21 21 environment. 22 22 23 23 Example: 24 24 … … 66 66 // Work derived from: 67 67 68 /* 68 /* 69 69 A C-program for MT19937, with initialization improved 2002/1/26. 70 70 Coded by Takuji Nishimura and Makoto Matsumoto. 71 71 72 Before using, initialize the state by using init_genrand(seed) 72 Before using, initialize the state by using init_genrand(seed) 73 73 or init_by_array(init_key, key_length). 74 74 75 75 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, 76 All rights reserved. 76 All rights reserved. 77 77 78 78 Redistribution and use in source and binary forms, with or without … … 87 87 documentation and/or other materials provided with the distribution. 88 88 89 3. The names of its contributors may not be used to endorse or promote 90 products derived from this software without specific prior written 89 3. The names of its contributors may not be used to endorse or promote 90 products derived from this software without specific prior written 91 91 permission. 92 92 … … 146 146 modulus = m; 147 147 } 148 148 149 149 static assert(isIntegral!(UIntType)); 150 150 static assert(m == 0 || a < m); … … 181 181 UIntType next() 182 182 { 183 static if (m) 183 static if (m) 184 184 _x = cast(UIntType) ((cast(ulong) a * _x + c) % m); 185 185 else … … 203 203 return _x == rhs._x; 204 204 } 205 205 206 206 private UIntType _x = 1; 207 207 }; … … 318 318 return result; 319 319 } 320 320 321 321 /** 322 322 Constructs a MersenneTwisterEngine object … … 334 334 } 335 335 for (mti = 1; mti < n; ++mti) { 336 mt[mti] = 336 mt[mti] = 337 337 cast(UIntType) 338 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> (w - 2))) + mti); 338 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> (w - 2))) + mti); 339 339 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 340 340 /* In the previous versions, MSBs of the seed affect */ … … 364 364 if (mti == n + 1) /* if init_genrand() has not been called, */ 365 365 seed(5489UL); /* a default initial seed is used */ 366 367 int kk = 0; 366 367 int kk = 0; 368 368 for (; kk < n - m; ++kk) 369 369 { … … 381 381 mt[n - 1] = cast(UIntType) (mt[m - 1] ^ (y >> 1) 382 382 ^ mag01[cast(UIntType) y & 0x1U]); 383 383 384 384 mti = 0; 385 385 } 386 386 387 387 y = mt[mti++]; 388 388 389 389 /* Tempering */ 390 390 y ^= (y >> temperingU); … … 392 392 y ^= (y << temperingT) & temperingC; 393 393 y ^= (y >> temperingL); 394 394 395 395 return cast(UIntType) y; 396 396 } … … 459 459 auto n = rnd.next; 460 460 ... 461 ---- 461 ---- 462 462 */ 463 463 … … 467 467 static MinstdRand0 rand; 468 468 if (!seeded) { 469 rand.seed(getpid ^ getUTCtime);469 rand.seed(getpid ^ cast(uint)getUTCtime); 470 470 seeded = true; 471 471 } … … 503 503 auto percentages = UniformDistribution!(double, "$(LPAREN)]")(0.0, 100.0); 504 504 // Get a digit in ['0', '9'] 505 auto digit = digits.next(gen); 505 auto digit = digits.next(gen); 506 506 // Get a number in $(LPAREN)0.0, 100.0] 507 507 auto p = percentages.next(gen); … … 545 545 /** 546 546 Returns the the right bound of the random value generated. 547 */ 547 */ 548 548 ResultType b() { return rightLim == ']' ? _b : nextLarger(_b); } 549 549 … … 585 585 } 586 586 } 587 588 private: 587 588 private: 589 589 NumberType _a = 0, _b = NumberType.max; 590 590 … … 739 739 Note: This is more random, but slower, than C's $(D rand()) function. 740 740 To use C's $(D rand()) instead, import $(D std.c.stdlib). 741 741 742 742 BUGS: Shares a global single state, not multithreaded. SCHEDULED FOR 743 743 DEPRECATION. trunk/phobos/std/signals.d
r464 r853 59 59 import std.stdio; 60 60 import std.c.stdlib : calloc, realloc, free; 61 import std.outofmemory : _d_OutOfMemory;61 import exception : onOutOfMemoryError; 62 62 63 63 // Special function for internal use only. … … 66 66 extern (C) Object _d_toObject(void* p); 67 67 68 // Used in place of Object.notifyRegister and Object.notifyUnRegister. 69 alias void delegate(Object) DisposeEvt; 70 extern (C) void rt_attachDisposeEvent( Object obj, DisposeEvt evt ); 71 extern (C) void rt_detachDisposeEvent( Object obj, DisposeEvt evt ); 68 72 //debug=signal; 69 73 … … 171 175 auto p = std.signals.calloc(slot_t.sizeof, len); 172 176 if (!p) 173 std.signals._d_OutOfMemory();177 onOutOfMemoryError(); 174 178 slots = (cast(slot_t*)p)[0 .. len]; 175 179 } … … 179 183 auto p = std.signals.realloc(slots.ptr, slot_t.sizeof * len); 180 184 if (!p) 181 std.signals._d_OutOfMemory();185 onOutOfMemoryError(); 182 186 slots = (cast(slot_t*)p)[0 .. len]; 183 187 slots[slots_idx + 1 .. length] = null; … … 188 192 L1: 189 193 Object o = _d_toObject(slot.ptr); 190 o.notifyRegister(&unhook);194 rt_attachDisposeEvent(o, &unhook); 191 195 } 192 196 … … 205 209 206 210 Object o = _d_toObject(slot.ptr); 207 o.notifyUnRegister(&unhook);211 rt_detachDisposeEvent(o, &unhook); 208 212 } 209 213 else … … 248 252 if (slot) 249 253 { Object o = _d_toObject(slot.ptr); 250 o.notifyUnRegister(&unhook);254 rt_detachDisposeEvent(o, &unhook); 251 255 } 252 256 } trunk/phobos/std/socket.d
r851 r853 3 3 /* 4 4 Copyright (C) 2004-2005 Christopher E. Miller 5 5 6 6 This software is provided 'as-is', without any express or implied 7 7 warranty. In no event will the authors be held liable for any damages 8 8 arising from the use of this software. 9 9 10 10 Permission is granted to anyone to use this software for any purpose, 11 11 including commercial applications, and to alter it and redistribute it 12 12 freely, subject to the following restrictions: 13 13 14 14 1. The origin of this software must not be misrepresented; you must not 15 15 claim that you wrote the original software. If you use this software … … 20 20 3. This notice may not be removed or altered from any source 21 21 distribution. 22 22 23 23 socket.d 1.3 24 24 Jan 2005 25 25 26 26 Thanks to Benjamin Herr for his assistance. 27 27 */ 28 28 29 29 /** 30 * Notes: For Win32 systems, link with ws2_32.lib. 30 * Notes: For Win32 systems, link with ws2_32.lib. 31 31 * Example: See /dmd/samples/d/listener.d. 32 * Authors: Christopher E. Miller 32 * Authors: Christopher E. Miller 33 33 * Macros: 34 34 * WIKI=Phobos/StdSocket … … 39 39 private import std.string, std.stdint, std.c.string, std.c.stdlib; 40 40 41 version(unittest) 42 { 43 private import std.c.stdio : printf; 44 } 45 41 46 42 47 version(linux) … … 53 58 private import std.c.windows.windows, std.c.windows.winsock; 54 59 private alias std.c.windows.winsock.timeval _ctimeval; 55 60 56 61 typedef SOCKET socket_t = INVALID_SOCKET; 57 62 private const int _SOCKET_ERROR = SOCKET_ERROR; 58 59 63 64 60 65 private int _lasterr() 61 66 { … … 70 75 private alias std.c.linux.linux.timeval _ctimeval; 71 76 } 72 77 73 78 typedef int32_t socket_t = -1; 74 79 private const int _SOCKET_ERROR = -1; 75 76 80 81 77 82 private int _lasterr() 78 83 { … … 90 95 { 91 96 int errorCode; /// Platform-specific error code. 92 97 93 98 this(string msg, int err = 0) 94 99 { 95 100 errorCode = err; 96 101 97 102 version(linux) 98 103 { … … 102 107 auto cs = strerror_r(errorCode, buf.ptr, buf.length); 103 108 auto len = strlen(cs); 104 109 105 110 if(cs[len - 1] == '\n') 106 111 len--; … … 110 115 } 111 116 } 112 117 113 118 super(msg); 114 119 } … … 121 126 { 122 127 WSADATA wd; 123 128 124 129 // Winsock will still load if an older version is present. 125 130 // The version is just a request. … … 192 197 string name; /// ditto 193 198 string[] aliases; /// ditto 194 195 199 200 196 201 void populate(protoent* proto) 197 202 { 198 203 type = cast(ProtocolType)proto.p_proto; 199 204 name = std.string.toString(proto.p_name).idup; 200 205 201 206 int i; 202 207 for(i = 0;; i++) … … 205 210 break; 206 211 } 207 212 208 213 if(i) 209 214 { … … 220 225 } 221 226 } 222 227 223 228 /** Returns false on failure */ 224 229 bool getProtocolByName(string name) … … 231 236 return true; 232 237 } 233 234 238 239 235 240 /** Returns false on failure */ 236 241 // Same as getprotobynumber(). … … 269 274 ushort port; /// ditto 270 275 string protocolName; /// ditto 271 272 276 277 273 278 void populate(servent* serv) 274 279 { … … 276 281 port = ntohs(cast(ushort)serv.s_port); 277 282 protocolName = std.string.toString(serv.s_proto).idup; 278 283 279 284 int i; 280 285 for(i = 0;; i++) … … 283 288 break; 284 289 } 285 290 286 291 if(i) 287 292 { … … 298 303 } 299 304 } 300 305 301 306 /** 302 307 * If a protocol name is omitted, any protocol will be matched. … … 312 317 return true; 313 318 } 314 315 319 320 316 321 // Any protocol name will be matched. 317 322 /// ditto … … 325 330 return true; 326 331 } 327 328 332 333 329 334 /// ditto 330 335 bool getServiceByPort(ushort port, string protocolName) … … 337 342 return true; 338 343 } 339 340 344 345 341 346 // Any protocol name will be matched. 342 347 /// ditto … … 378 383 { 379 384 int errorCode; /// Platform-specific error code. 380 381 385 386 382 387 this(string msg, int err = 0) 383 388 { … … 396 401 string[] aliases; /// ditto 397 402 uint32_t[] addrList; /// ditto 398 399 403 404 400 405 void validHostent(hostent* he) 401 406 { … … 403 408 throw new HostException("Address family mismatch", _lasterr()); 404 409 } 405 406 410 411 407 412 void populate(hostent* he) 408 413 { 409 414 int i; 410 415 char* p; 411 416 412 417 name = std.string.toString(he.h_name).idup; 413 418 414 419 for(i = 0;; i++) 415 420 { … … 418 423 break; 419 424 } 420 425 421 426 if(i) 422 427 { … … 432 437 aliases = null; 433 438 } 434 439 435 440 for(i = 0;; i++) 436 441 { … … 439 444 break; 440 445 } 441 446 442 447 if(i) 443 448 { … … 453 458 } 454 459 } 455 460 456 461 /** 457 462 * Resolve host name. Returns false if unable to resolve. 458 */ 463 */ 459 464 bool getHostByName(string name) 460 465 { … … 467 472 return true; 468 473 } 469 470 474 475 471 476 /** 472 477 * Resolve IPv4 address number. Returns false if unable to resolve. 473 */ 478 */ 474 479 bool getHostByAddr(uint addr) 475 480 { … … 483 488 return true; 484 489 } 485 486 490 491 487 492 /** 488 493 * Same as previous, but addr is an IPv4 address string in the 489 494 * dotted-decimal form $(I a.b.c.d). 490 495 * Returns false if unable to resolve. 491 */ 496 */ 492 497 bool getHostByAddr(string addr) 493 498 { … … 517 522 printf("aliases[%d] = %.*s\n", i, s); 518 523 } 519 524 520 525 printf("---\n"); 521 526 522 527 assert(ih.getHostByAddr(ih.addrList[0])); 523 528 printf("name = %.*s\n", ih.name); … … 559 564 protected: 560 565 sockaddr sa; 561 562 566 567 563 568 override sockaddr* name() 564 569 { 565 570 return &sa; 566 571 } 567 568 572 573 569 574 override int nameLen() 570 575 { 571 576 return sa.sizeof; 572 577 } 573 574 578 579 575 580 public: 576 581 override AddressFamily addressFamily() … … 578 583 return cast(AddressFamily)sa.sa_family; 579 584 } 580 581 585 586 582 587 override string toString() 583 588 { … … 601 606 return cast(sockaddr*)&sin; 602 607 } 603 604 608 609 605 610 override int nameLen() 606 611 { 607 612 return sin.sizeof; 608 613 } 609 610 614 615 611 616 this() 612 617 { 613 618 } 614 615 619 620 616 621 public: 617 622 const uint ADDR_ANY = INADDR_ANY; /// Any IPv4 address number. 618 623 const uint ADDR_NONE = INADDR_NONE; /// An invalid IPv4 address number. 619 624 const ushort PORT_ANY = 0; /// Any IPv4 port number. 620 625 621 626 /// Overridden to return AddressFamily.INET. 622 627 override AddressFamily addressFamily() … … 624 629 return cast(AddressFamily)AddressFamily.INET; 625 630 } 626 631 627 632 /// Returns the IPv4 port number. 628 633 ushort port() … … 630 635 return ntohs(sin.sin_port); 631 636 } 632 637 633 638 /// Returns the IPv4 address number. 634 639 uint addr() … … 636 641 return ntohl(sin.sin_addr.s_addr); 637 642 } 638 643 639 644 /** 640 645 * Params: … … 659 664 sin.sin_port = htons(port); 660 665 } 661 666 662 667 /** 663 668 * Construct a new Address. addr may be ADDR_ANY (default) and port may … … 670 675 sin.sin_port = htons(port); 671 676 } 672 673 /// ditto 677 678 /// ditto
