delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/10/11/13:25:55

From: grimm AT itd DOT nrl DOT navy DOT mil (Todd M. Grimm)
Subject: Re: select()
11 Oct 1998 13:25:55 -0700 :
Message-ID: <Pine.SUN.3.91.981011095902.22891A-300000.cygnus.gnu-win32@grout>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 981009090931 DOT 7098A-300000 AT grout>
Mime-Version: 1.0
To: gnu-win32 AT cygnus DOT com

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime AT docserver DOT cac DOT washington DOT edu for more info.

---2138520006-1113834566-908114887=:22891
Content-Type: TEXT/PLAIN; charset=US-ASCII

Thanks to all those who responded to my select() problems. I have found my 
solution. Maybe this is what ails some of you with similar problems, 
maybe your problem is something different.

To recap, my receiving process was hanging on select() at the start even 
though there was data. When a key (even shift) was pressed in the shell 
window it would unhang and consume the already waiting data. The other 
problem was that all calls to select() after that returned with a value 
of 1 even when there was no data on the socket.

It turns out that at run-time or maybe at link time, the select() that is 
used is the unix kind that that uses the bit mask to specify what file 
descriptors are being watched. However, the include files I was using use 
some kind of Windows version that uses a structure with an array in it. 

So, when the bitmask version tried to use the structure I was passing it, 
it looked like a bitmask that wanted it to check stdin all the time. This 
explains the bad behavior. The solution is to simple use the right 
include files with the bitmask macros (FD_SET, FD_ZERO, etc.). That way 
what I build and pass really is the bitmask and it works just fine.

These are those simple little platform issues that really bite you good.

I hope this helps someone else avoid the watsed hours this cost me.

Attached are my simple demo programs that do it right now. These may be 
useful to someone looking for a starting point or to see what they do for 
includes that works.

Todd

---2138520006-1113834566-908114887=:22891
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="SimpleServer.C"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine DOT SUN DOT 3 DOT 91 DOT 981011100807 DOT 22891B AT grout>
Content-Description: 

Ly8gLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t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XplX3QpIDk5OSk7DQogICAgaWYgKGJ5dGVz
cmVhZCA9PSAwKSBicmVhazsNCiAgICBidWZmW2J5dGVzcmVhZF0gPSAwOw0K
ICAgIGNlcnIgPDwgInJlYWQgdGhpcyAjIiA8PCBidWZmIDw8ICIjIiA8PCBl
bmRsOw0KICB9DQogIGNlcnIgPDwgImdvdCBlb2YiIDw8IGVuZGw7DQp9DQoN
Ci8vIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0g
ZW5kIGZpbGUgU2ltcGxlU2VydmVyLkMNCg==
---2138520006-1113834566-908114887=:22891
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="SimpleClient.C"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine DOT SUN DOT 3 DOT 91 DOT 981011100807 DOT 22891C AT grout>
Content-Description: 

Ly8gLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSBi
ZWdpbiBmaWxlIFNpbXBsZUNsaWVudC5DDQoNCi8vIGNvbXBpbGUgY29tbWFu
ZDogZ2NjIC1vIFNpbXBsZUNsaWVudCBTaW1wbGVDbGllbnQuQyAtbHN0ZGMr
Kw0KLy8gb24gU29sYXJpcyB5b3UgbWF5IGFsc28gbmVlZDogLWxzb2NrZXQg
LWxuc2wNCg0KLy8gc2VlIHRlc3QgaW5zdHJ1Y3Rpb25zIGluIFNpbXBsZVNl
cmV2ci5DDQoNCg0KI2luY2x1ZGUgPHN0ZGxpYi5oPg0KI2luY2x1ZGUgPHN0
ZGlvLmg+DQojaW5jbHVkZSA8ZnN0cmVhbS5oPg0KI2luY2x1ZGUgPGZjbnRs
Lmg+DQojaW5jbHVkZSA8dW5pc3RkLmg+DQojaW5jbHVkZSA8c3RyaW5nLmg+
DQoNCiNpZmRlZiBXSU5OVA0KDQovLyAqKioqKioqKioqKioqKioqKiBoZXJl
J3Mgd2hlcmUgdGhlIHByb2JsZW0gd2FzICoqKioqKioqK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gc2l6ZW9mKGFkZHIpKSkgeyBwZXJyb3IgKCJzb2NrZXRQcmVwIC0gY29u
bmVjdGluZyBzb2NrZXQiKTsgZXhpdCgtMSk7IH0NCiAgY2VyciA8PCAic29j
a2V0UHJlcCAtIGNsaWVudCBzaWRlIGNvbm5lY3RlZCIgPDwgZW5kbDsNCn0N
Cg0KDQppbnQgbWFpbiAoaW50IGFyZ2MsIGNoYXIgKiphcmd2KQ0Kew0KICBj
aGFyIGJ1ZmZbMTAwMF07DQogIGJ1ZmZbMF0gPSAnQSc7IA0KICBidWZmWzFd
ID0gMDsNCiAgaW5pdCgpOyAvLyBvcGVuIHRoZSBzb2NrZXQNCiAgY2VyciA8
PCAic2VuZGluZyBmaXJzdCBtZXNzYWdlIGluIDMgc2Vjb25kcyIgPDwgZW5k
bDsgc2xlZXAoMyk7DQoNCiAgd2hpbGUoMSkNCiAgew0KICAgIGludCBsZW4g
PSBzdHJsZW4oYnVmZik7DQogICAgd3JpdGUoZmQsIGJ1ZmYsIGxlbik7DQog
ICAgY2VyciA8PCAic2VudCB0aGlzICMiIDw8IGJ1ZmYgPDwgIiMiIDw8IGVu
ZGw7DQogICAgYnVmZltsZW5dICAgPSAneCc7DQogICAgYnVmZltsZW4rMV0g
PSAwOw0KICAgIGNlcnIgPDwgInNsZWVwaW5nIiA8PCBlbmRsOw0KICAgIHNs
ZWVwKDEwKTsNCiAgfQ0KfQ0KDQovLyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tIGVuZCBmaWxlIFNpbXBsZUNsaWVudC5DDQo=
---2138520006-1113834566-908114887=:22891--
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019