www.digitalmars.com         C & C++   DMDScript  

D - a new version of socket.d

reply "Christian Lesage" <christian.lesage.1 agora.ulaval.ca> writes:
Hi folks,

I found two bugs in Pavel Minayev's "socket.d", which is, I believe, a great
module to play with if you need TCP/IP in your apps. I'm posting an updated
version of it along with a slightly modified version of Pavel's sample
program. Is there a better place to send files to, so that everybody can
access them?

The first bug was due to the fact that you can't instantiate an object from
a class which has, somewhere in it's ancestry, an abstract method left
undefined. The TCPSocket class inherits from the StreamSocket class which
inherits from the Stream class which has three abstract methods. One of
these, seek(), was left undefined in the sub-classes. I just defined a dummy
seek() method in StreamSocket to circumvent the problem. Should it be done
otherwise?

The second bug concerned the initialization of an IP address (within the IP
class) using a hostname. It was broken because it didn't use correctly the
data structure returned by gethostbyname(). A char** has to be dereferenced
twice...

Not bad for a newbie, uh? I think I'm going to love D.


Thanks to Lars Ivar Igesund for his hint regarding abstract classes.

Christian Lesage


begin 666 socket.d
M+RHA#0H *B!3;V-K971S(&9O<B!$#0H *B!#;W!Y<FEG:'0 *&,I(#(P,#( 
M4&%V96P (D5V:6Q/;F4B($UI;F%Y978-"B J($-O<'ER:6=H=" H8RD ,C P
M,R!-:6ME(%=Y;FX /&UI:V4N=WEN;D!L.&YI9VAT+F-O+G5K/ T*("H 1FEX
M960 8GD 0VAR:7-T:6%N($QE<V%G92!O;B!T:&4 .'1H(&]F(&]C=&]B97(L
M(#(P,#,N("A3964 8V]M;65N=',I#0H * T*("H 4&5R;6ES<VEO;B!T;R!U
M<V4L(&-O<'DL(&UO9&EF>2P 9&ES=')I8G5T92!A;F0 <V5L;"!T:&ES('-O
M9G1W87)E#0H *B!A;F0 :71S(&1O8W5M96YT871I;VX 9F]R(&%N>2!P=7)P
M;W-E(&ES(&AE<F5B>2!G<F%N=&5D('=I=&AO=70 9F5E+ T*("H <')O=FED
M960 =&AA="!T:&4 86)O=F4 8V]P>7)I9VAT(&YO=&EC92!A<'!E87( :6X 
M86QL(&-O<&EE<R!A;F0-"B J('1H870 8F]T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!S;V-K970-"B\O(&EN(&9O<FT ;V8 8GET
M92!S=')E86T *%=I;E-O8VLR(%-/0TM?4U1214%-*0T*8VQA<W, 4W1R96%M
M4V]C:V5T.B!3=')E86T-"GL-" EP<F]T96-T960 4T]#2T54('-O8VME=" ]
M(&-A<W0H4T]#2T54*3 [#0H)#0H)+R\ 8FEN9', ;V)J96-T('1O(&%N(&5X
M:7-T:6YG('-O8VME=#L =7-E('=I=&  8V%R92$)#0H)=&AI<RA33T-+150 
M<RP 8FET(&-O;FYE8W1E9"D-" E[#0H)"7-O8VME=" ](',[#0H)"7)E861A
M8FQE(#T =W)I=&5A8FQE(#T 8V]N;F5C=&5D.PT*"7T-" T*"71H:7,H*2![
M?0T*#0H)#0H)+R\ <F5T=7)N<R!T<G5E(&EF('-O8VME="!I<R!C;VYN96-T
M960L(&9A;'-E(&]T:&5R=VES90T*"6)I="!C;VYN96-T960H*0T*"7L-" D)
M=6EN="!N8B ](#$[#0H)"6EO8W1L<V]C:V5T*'-O8VME="P 1DE/3D))3RP 
M)FYB*3L-" D)8VAA<B!B=68[#0H)"6EN="!R97-U;'0 /2!R96-V*'-O8VME
M="P )F)U9BP ,2P 35-'7U!%14LI.PT*"0EI;G0 97)R(#T 5U-!1V5T3&%S
M=$5R<F]R*"D[#0H)"6YB(#T ,#L-" D):6]C=&QS;V-K970H<V]C:V5T+"!&
M24].0DE/+" F;F(I.PT*"0EI9B H<F5S=6QT(#T](%-/0TM%5%]%4E)/4BD-
M" D)"7)E='5R;B H97)R(#T](%=304573U5,1$),3T-+*3L-" D)96QS90T*
M"0D)<F5T=7)N("AR97-U;'0A/3 I.PT*"7T-" D-" DO+R!D:7-C;VYN96-T
M<R!T:&4 <V]C:V5T#0H)=F]I9"!D:7-C;VYN96-T*"D-" E[#0H)"6EF("AS
M;V-K970I#0H)"7L-" D)"7-H=71D;W=N*'-O8VME="P 4T1?0D]42"D[#0H)
M"0EC;&]S97-O8VME="AS;V-K970I.PT*"0D)<F5A9&%B;&4 /2!W<FET96%B
M;&4 /2!F86QS93L-" D)"7-O8VME=" ](&-A<W0H4T]#2T54*3 [#0H)"7T-
M" E]#0H-" DO+R!R971U<FYS('1R=64 :68 =&AE<F4 :7, <F5C96EV960 
M9&%T82!I;B!T:&4 8G5F9F5R+ T*"2\O('-O(&-A;&P =&\ <F5A9" I('=O
M=61L;B=T(&)L;V-K+"!F86QS92!O=&AE<G=I<V4-" EB:70 9&%T85)E8V5I
M=F5D*"D-" E[#0H)"7-T871I8R!T:6UE=F%L('1V(#T >R P+" P('T[#0H)
M"69D7W-E="!F9#L-" D)1D1?6D523R F9F0I.PT*"0E&1%]3150H8V%S="A3
M3T-+150I('-O8VME="P )F9D*3L-" D)<F5T=7)N('-E;&5C=" P+" F9F0L
M(&YU;&PL(&YU;&PL("9T=BD /B P.PT*"7T-" D-" EO=F5R<FED92!U:6YT
M(')E861";&]C:RAV;VED*B!B=69F97(L('5I;G0 <VEZ92D-" DO+R!S:6YC
M92!I;BUB;&]C:W, 87)E(&YO="!I;FAE<FET960L(')E9&5F:6YE('1H96T-
M" EI; T*"7L-" D)87-S97)T*')E861A8FQE*3L-" E]#0H)8F]D>0T*"7L-
M" D):6YT(')E<W5L=" ](')E8W8H<V]C:V5T+"!C87-T*&-H87(J*2!B=69F
M97(L('-I>F4L(# I.PT*"0EI9B H(7)E<W5L="D-" D)"61I<V-O;FYE8W0H
M*3L-" D)96QS92!I9B H<F5S=6QT(#T](%-/0TM%5%]%4E)/4BD-" D)>PT*
M"0D)<W=I=&-H("AR97-U;'0I#0H)"0E[#0H)"0EC87-E(%=3045.3U1#3TY.
M. T*"0D)8V%S92!74T%%0T].3E)%4T54. T*"0D)"61I<V-O;FYE8W0H*3L-
M" D)"0ER971U<FX ,#L-" D)"6-A<V4 5U-!14-/3DY!0D]25$5$. T*"0D)
M8V%S92!74T%%3D544D53150Z#0H)"0D)9&ES8V]N;F5C=" I.PT*"0D)9&5F
M875L=#H-" D)"0ET:')O=R!N97< 0V]N;F5C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:6]N('!A<W-E<R!C;VYT<F]L('1O('-I
M;7!L:69I960 =F5R<VEO;B!W:&EC: T*"2\O(&1O97-N)W0 =&%K92!)4"!A
M;F0 <&]R="!P87)A;65T97)S#0H)<')O=&5C=&5D('9O:60 ;VY#;VYN96-T
M:6]N*%-T<F5A;5-O8VME="!S+"!);G1E<FYE=$%D9')E<W, :6$I#0H)>PT*
M"0EO;D-O;FYE8W1I;VXH<RD[#0H)?0T*#0H)+R\ <F5C96EV97, 8V]N=')O
M;"!W:&5N('-E<G9E<DQO;W H*2!A8V-E<'1S(&$ ;F5W(&-O;FYE8W1I;VXL
M#0H)+R\ =6YL97-S('1H92!M;W)E(&=E;F5R:6, =F5R<VEO;B!I<R!O=F5R
M<FED96X-" EP<F]T96-T960 =F]I9"!O;D-O;FYE8W1I;VXH4W1R96%M4V]C
M:V5T(',I('L ?0T*#0H)+R\ =7-E9"!I;G1E<FYA;&QY('1O('!A<W, 9&%T
M82!T;R!O=&AE<B!T:')E861S#0H)<')I=F%T92!C;&%S<R!C;VYN7V1A=&$-
M" E[#0H)"7!U8FQI8R!T:&ES*"!40U!397)V97( <V5R=F5R,"P 4W1R96%M
M4V]C:V5T('-O8VME=# L($EN=&5R;F5T061D<F5S<R!I83  *0T*"0E[#0H)
M"0ES97)V97( /2!S97)V97(P.PT*"0D)<V]C:V5T(#T <V]C:V5T,#L-" D)
M"6EA("  (" ](&EA,#L-" D)?0T*#0H)"51#4%-E<G9E<B!S97)V97([#0H)
M"5-T<F5A;5-O8VME="!S;V-K970[#0H)"4EN=&5R;F5T061D<F5S<R!I83L-
M" E]#0H)"0T*"7!R:79A=&4 97AT97)N*$,I('-T871I8R!V;VED(&-O;FYE
M8W1I;VY4:')E860H=F]I9"H 87)G*0T*"7L-" D)8V]N;E]D871A(&-N(#T 
M8V%S="AC;VYN7V1A=&$I(&%R9SL-" D)8VXN<V5R=F5R+F]N0V]N;F5C=&EO
M;BAC;BYS;V-K970L(&-N+FEA*3L-" E]#0H-" EP<FEV871E(&5X=&5R;BA#
M*2!S=&%T:6, =F]I9"!B9U-E<G9E<E1H<F5A9"AV;VED*B!A<F<I#0H)>PT*
M"0E40U!397)V97( <W9R(#T 8V%S="A40U!397)V97(I(&%R9SL-" D)<W9R
M+G-E<G9E<DQO;W H*3L-" E]#0I]#0H-"B\O(&-O;FYE8W1I;VYL97-S+"!M
M97-S86=E+6]R:65N=&5D('-O8VME=', *%=I;E-O8VLR(%-/0TM?1$=204TI
M#0IC;&%S<R!$871A9W)A;5-O8VME= T*>PT*"7!R;W1E8W1E9"!33T-+150 
M<V]C:V5T.PT*#0H)?G1H:7,H*0T*"7L-" D)<VAU=&1O=VXH<V]C:V5T+"!3
M1%]"3U1(*3L-" D)8VQO<V5S;V-K970H<V]C:V5T*3L-" E]#0H-" DO+R!R
M971U<FYS('1R=64 :68 =&AE<F4 :7, <F5C96EV960 9&%T82!I;B!T:&4 
M8G5F9F5R+"!S;PT*"2\O(&-A;&P =&\ <F5A9"!F=6YC=&EO;G, =VEL;"!N
M;W0 8FQO8VLL(&9A;'-E(&]T:&5R=VES90T*"6)I="!D871A4F5C96EV960H
M*0T*"7L-" D)<W1A=&EC('1I;65V86P ='8 /2![(# L(#  ?3L-" D)9F1?
M<V5T(&9D.PT*"0E&1%]:15)/*"9F9"D[#0H)"49$7U-%5"AC87-T*%-/0TM%
M5"D <V]C:V5T+" F9F0I.PT*"0ER971U<FX <V5L96-T*# L("9F9"P ;G5L
M;"P ;G5L;"P )G1V*2 ^(# [#0H)?0T*"0T*"2\O(')E='5R;G, <VEZ92!O
M9B!T:&4 ;&%R9V5S="!D871A9W)A;2!T:&ES('-O8VME="!C86X :&%N9&QE
M#0H)=6EN="!M87A$871A9W)A;2 I#0H)>PT*"0EU:6YT(')E<W5L=#L-" D)
M:6YT(')L96X /2!R97-U;'0N<VEZ93L-" D)9V5T<V]C:V]P="AS;V-K970L
M(%-/3%]33T-+150L(%-/7TU!6%]-4T=?4TE:12P-" D)"6-A<W0H8VAA<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W0H8VAA<BHI(&)L;V-K+"!S:7IE+ T*"0D),"P 8V%S="AS;V-K861D<BHI
M("9S82P )G-A;&5N*3L-" D):68 *')E<W5L=" ]/2!33T-+151?15)23U(I
M#0H)"7L-" D)"6EF("A74T%'971,87-T17)R;W(H*2 ]/2!74T%%35-'4TE:
M12D-" D)"0ER97-U;'0 /2!S:7IE("L ,3L-" D)"65L<V4-" D)"0ET:')O
M=R!N97< 4F5A9$5R<F]R*")S;V-K970 9F%I;&5D('1O(')E8V5I=F4 9&%T
M86=R86TB*3L-" D)?0T*"0EI82YI<"YI<&%D9'(N861D<F5S<R ]('-A+G-I
M;E]A9&1R+G-?861D<CL-" D):6$N<&]R=" ](&YT;VAS*'-A+G-I;E]P;W)T
M*3L-" D)<F5T=7)N(')E<W5L=#L-" E]#0I]#0H-"B\O('-T<F5A;2 H5$-0
M*2!S;V-K971S(&%R92!U<V5D(&UO<F4 9G)E<75E;G1L>2P-"B\O('-O('-U
M8V  86X 86QI87, <V5E;7, ;&]G:6-A; T*86QI87, 4W1R96%M4V]C:V5T
((%-O8VME=#L`
`
end

begin 666 HTTPGET.D
M+RH-"B J(%-I;7!L:7-T:6, 2%144"!C;&EE;G0 <V%M<&QE('=R:71T96X 
M:6X 1 T*("H 0V]P>7)I9VAT("AC*2 R,# R(%!A=F5L(")%=FEL3VYE(B!-
M:6YA>65V#0H * T*("H 4&5R;6ES<VEO;B!T;R!U<V4L(&-O<'DL(&UO9&EF
M>2P 9&ES=')I8G5T92!A;F0 <V5L;"!T:&ES('-O9G1W87)E#0H *B!A;F0 
M:71S(&1O8W5M96YT871I;VX 9F]R(&%N>2!P=7)P;W-E(&ES(&AE<F5B>2!G
M<F%N=&5D('=I=&AO=70 9F5E+ T*("H <')O=FED960 =&AA="!T:&4 86)O
M=F4 8V]P>7)I9VAT(&YO=&EC92!A<'!E87( :6X 86QL(&-O<&EE<R!A;F0-
M"B J('1H870 8F]T:"!T:&%T(&-O<'ER:6=H="!N;W1I8V4 86YD('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YT
M(#X ,3 R-"D-" D)>PT*"0D)<')I;G1F*"(N(BD[#0H)"0EC;W5N=" ](# [
M#0H)"7T-" E]#0H)#0H)<')I;G1F*")<;EQN)2XJ<UQN(BP 9FEL92D[#0H)
M<')I;G1F*")(:70 82!K97DN+BY<;B(L(&9I;&4I.PT*"7=H:6QE("  (6MB
::&ET*"D *2![?2 -" ER971U<FX ,#L-"GT`
`
end
Oct 08 2003
parent Brad Anderson <brad sankaty.com> writes:
 One of
 these, seek(), was left undefined in the sub-classes. I just defined a dummy
 seek() method in StreamSocket to circumvent the problem. Should it be done
 otherwise?
 
 The second bug concerned the initialization of an IP address (within the IP
 class) using a hostname. It was broken because it didn't use correctly the
 data structure returned by gethostbyname(). A char** has to be dereferenced
 twice...
 
Bravo! I was struggling with seek() a few weeks back. I can't think of another way to do it, but I'll let you know how it works in my app... Thanks, Brad
Oct 09 2003