This=20mail=20is=20addressed=20to=20Dr=20Stephen=2 0N.=20Henson=20in=20con=
nection=20with=20his=20previous=20post.


>=20I=20have=20never=20come=20across=20a=20report=2 0of=20a=20deadlock=20i=

n=20that=20situation=20and=20several
>=20applications=20have=20reported=20using=20WSAEve ntSelect()=20in=20the=20=

past.=20There=20are
>=20several=20possible=20reasons...
>



There=20is=20very,very=20little=20chance=20the=20a pplication=20to=20deadl=
ock.=20'send'=20command=20fails=20very=20rare.=20I =20have=20made=20a=20te=
st=20-=20I've=20sent=20about=20100=20Mb=20at=20one=20tim e=20using=20nonbl=
ocking=20socket=20and=20windows=20consumed=20whole =20buffer=20at=20one=20=
time=20and=20immediately=20returned=20without=20=2 0any=20error=20and=20wi=
th=20100=20Mb=20send=20(the=20data=20wasn't=20send =20of=20course)=20-=20i=
t=20means=20that=20it=20has=20large=20enough=20buf fer=20to=20consume=20bi=
g=20amount=20of=20data.=20I'm=20using=20windows=20 xp,=20i=20don't=20know=20=
how=20it=20works=20on=20older=20systems=20(NT,98,m e)=20maybe=20there=20is=
=20bigger=20probability=20to=20'send'=20failure.=2 0=20That's=20not=20all,=
=20i'm=20coding=20simple=20jabber=20client=20(i=20 hope=20you=20know=20wha=
t=20is=20jabber).=20I've=20downloaded=20source=20c ode=20for=20one=20of=20=
the=20freeware=20clients=20recommended=20by=20main =20jabber.org=20site=20=
(by=20the=20way,=20this=20client=20is=20recommende d=20at=20first=20place=20=
as=20windows=20client).=20I've=20looked=20at=20sou rce=20and=20it=20seems=20=
that=20it=20uses=20openSSL=20improperly=20-=20in=20winsock=20fashion=20(w=
hich=20is=20good=20for=20unencrypted=20connection= 20-=20it=20depends=20on=
=20jabber=20server),using=202=20thread=20one=20for =20reading=20and=20one=20=
for=20writing,=20without=20any=20openSSL=20command =20serialization.=20(Th=
is=20is=20my=20opinion,=20maybe=20i've=20missed=20 something=20but=20i=20d=
on't=20think=20so,=20it's=20written=20in=20delphi= 20and=20it=20uses=20ind=
y=20components)=20But=20even=20using=20this=20rath er=20improper=20for=20o=
penSSL=20style,=20it=20seems=20that=20it=20doesn't =20cause=20much=20troub=
le.=20Probability=20of=20reading=20and=20writing=2 0exactly=20at=20the=20s=
ame=20time=20for=20communicator=20application=20is =20rather=20small,=20ad=
ditionally=20scheduler=20must=20switch=20the=20thr eads=20in=20special=20m=
oment=20of=20their=20work=20to=20cause=20race=20co ndition.=20So,=20deadlo=
cks=20for=20most=20application=20are=20very=20rare =20and=20it=20is=20rath=
er=20matter=20of=20correctness=20then=20real=20pro blem=20in=20real=20appl=
ications=20causes=20me=20to=20find=20proper=20way= 20of=20implementing=20O=
penSSL=20app.

>=201.=20The=20application=20works=20because=20of=2 0the=20feature=20menti=

oned=20in=20KB186245.
>=20


I'm=20using=20XP

>=202.=20The=20send()=20function=20never=20returns= 20any=20of=20the=20oth=

er=20BIO=5Fsock=5Fnon=5Ffatal=5Ferror
>=20codes=20so=20this=20is=20not=20an=20issue=20in= 20practice.=20The=20do=

cumentation=20seems=20to=20suggest
>=20this=20but=20that's=20no=20guarantee.
>=20


Well,=20that's=20the=20problem.=20I=20have=20no=20 certainty=20that=20this=
=20is=20true=20and=20it=20will=20be=20true=20for=2 0further=20openSSL=20im=
plementations,=20so=20i=20have=20to=20develop=20co de=20to=20deal=20with=20=
it.


>=20Call=20select()=20with=20a=20zero=20second=20ti meout.=20If=20it=20ind=

icates=20socket=20is
>=20writable=20retry=20the=20opertion,=20if=20not=2 0call=20WSAEventSelect=

().


Theoretically=20this=20should=20be=20true=20since= 20if=20openSSL=20return=
s=20error=20WANT=5FWRITE=20and=20it=20is=20not=20c aused=20by=20WSAEWOULBL=
OCK=20(FD=5FWRITE=20event=20won't=20be=20send)=20i t=20means=20that=20oper=
ation=20should=20just=20be=20immediatelly=20repeat ed=20and=20'select'=20c=
an=20be=20used=20to=20check=20this=20situation.=20 But=20very=20theoretica=
lly=20i=20some=20case=20WANT=5FWRITE=20will=20not= 20be=20send=20since=20w=
indows=20can't=20check=20when=20writing=20will=20b e=20possible.=20Windows=
=20signals=20this=20returning=20error=20other=20th en=20WSAEWOULDBLOCK=20a=
nd=20some=20other=20checking=20method=20should=20b e=20used,=20for=20examp=
le:=20repeated=20socket=20polling=20('select'=20wi th=20timeout=20>=200).(=
I=20hope=20you=20know=20what=20i=20mean)=20I=20kno w=20this=20is=20very=20=
abstract=20case,=20but=20it=20should=20reminded=20 that=20OS=20API=20is=20=
something=20what=20is=20developed=20by=20many=20ye ars=20for=20different=20=
OS=20versions,=20sometimes=20API=20is=20imported=2 0for=20compatibility=20=
from=20diffrent=20OSes,=20etc.=20So=20using=20only =20good=20sense=20is=20=
not=20reliable=20way=20to=20success.=20(for=20exam ple=20why=20'select'=20=
doesn't=20support=20socket=20and=20pipes=20at=20th e=20same=20time?=20Won'=
t=20it=20be=20better=20then=20implementing=20WSAXX X=20framework?).=20The=20=
only=20reliable=20way=20is=20to=20implement=20exca ctly=20with=20OS=20API=20=
specyfication.

>=20
>=20Call=20WSAGetLastError()=20to=20confirm=20the=2 0error=20code.
>=20


Yes,i=20have=20seen=20this=20method=20in=20some=20 thread=20of=20this=20ma=
iling=20list,=20but=20i=20think=20that=20it's=20no t=20reliable=20method.=20=
I=20have=20no=20certainty=20that=20OpenSSL=20doesn 't=20reset=20error=20co=
de=20or=20some=20other=20windows=20command=20is=20 not=20invoked=20after=20=
'send'=20failure.

>=20
>=20One=20is=20to=20write=20a=20custom=20socket=20B IO.=20In=20this=20case=

=20it=20would=20be=20very=20simple
>=20because=20it=20would=20copy=20all=20the=20exist ing=20methods=20*excep=

t*=20the=20write=20behaviour
>=20which=20would=20set=20the=20retry=20flag=20only =20if=20the=20error=20=

is=20WSAEWOULDBLOCK.
>


Unfortunately=20i'm=20using=20Delphi=20and=20openS SL=20is=20written=20in=20=
c,=20so=20it's=20not=20such=20easy=20for=20me.

=20
>=20The=20second=20alternative=20is=20BIO=20pairs=2 0this=20give=20an=20ap=

plication=20total=20flexibility
>=20on=20all=20socket=20I/O=20but=20is=20more=20complex=20to=20handle.
>=20


Yes,=20much=20more.


I've=20developed=20some=20method,=20but=20i=20has= 20limited=20usage,=20it=
=20can=20be=20used=20for=20some=20special=20kind=2 0of=20applications=20us=
ing=20one=20socket=20for=20reading=20and=20writing .=20(but=20this=20is=20=
exactly=20my=20case)=20Application=20must=20wait=2 0for=203=20events:=20re=
ading=20event,user=20event(used=20to=20tell=20that =20user=20want=20write)=
=20and=20write=20event(used=20only=20if=20WANT=5FW RITE=20occured).=20This=
=20trick=20is=20tightly=20connected=20with=20appli cation=20logic.When=20a=
pp=20starts=20it=20waits=20for=202=20events:=20FD= 5FREAD=20event=20and=20=
user=20event,=20it=20does=20it=20using=20'WaitForM ultipleObjects'=20comma=
nd.=20It=20uses=20this=20construction=20all=20time =20till=20WANT=5FWRITE=20=
error=20will=20occur,=20then=20it=20can=20switch=2 0to=20loop=20which=20us=
es=20'select'=20statement=20as=20blocking=20functi on=20-=20the=20trick=20=
is=20very=20simple,=20when=20app=20can't=20write=2 0it=20doesn't=20have=20=
to=20wait=20for=20user=20event,
so=20'select'=20statement=20can=20be=20used.=20Whe n=20'select'=20returns=20=
ability=20to=20write=20app=20can=20again=20switch= 20to=20'WaitForMultiple=
Objects'=20and=20so=20on.=20Do=20you=20ever=20came =20across=20this=20impl=
ementation?=20What=20do=20you=20think=20abou=20it? =20Have=20i=20missed=20=
something?=20=20

=20
I=20have=20one=20question=20to=20you,=20yet.=20If= 20SSL=5Fwrite=20blocks=20=
with=20WANT=5FWRITE=20error,=20theoretically=20i=2 0can=20still=20use=20SS=
L=5Fread=20?=20(I=20think=20i=20can).=20But=20what =20to=20do=20when=20SSL=
=5Fread=20will=20return=20WANT=5FWRITE=20error?=20 Which=20command=20i=20s=
hould=20repeat=20first?=20SSL=5Fread,=20SSL=5Fwrit e=20or=20it=20doesn't=20=
metter?

Lucas

__________________________________________________ ____________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-dev@openssl.org
Automated List Manager majordomo@openssl.org