[PATCH] Handful of fixes for swazoo

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Handful of fixes for swazoo

Paolo Bonzini-2
Bugs found while porting...

Paolo

2008-02-06  Paolo Bonzini  <[hidden email]>

        * kernel/SeqCollect.st: Don't fail in #copyUpTo: if the character
        is not there, return the whole collection instead.

        * packages/sport/sport.st: Fix sockets for Swazoo.
        Add SpFilename>>#name.

        * packages/tcp/Sockets.st: Add methods needed by Sport.

diff --git a/kernel/SeqCollect.st b/kernel/SeqCollect.st
index 97c3e1b..583e0d5 100644
--- a/kernel/SeqCollect.st
+++ b/kernel/SeqCollect.st
@@ -532,8 +532,7 @@ some access and manipulation methods.'>
  <category: 'copying SequenceableCollections'>
  ^self copyFrom: 1
     to: (self indexOf: anObject
-    ifAbsent: [^SystemExceptions.NotFound signalOn: anObject what: 'object'])
- - 1
+    ifAbsent: [self size + 1]) - 1
     ]
 
     copyReplaceFrom: start to: stop withObject: anObject [
diff --git a/packages/sport/sport.st b/packages/sport/sport.st
index a794a0a..f959610 100644
--- a/packages/sport/sport.st
+++ b/packages/sport/sport.st
@@ -382,7 +382,7 @@ Object subclass: SpEnvironment [
 
  <category: 'compiling'>
  ^Behavior
-    evaluate: aString for: anObject
+    evaluate: aString to: anObject
     ]
 
     SpEnvironment class >> hexStringFromByteArray: aByteArray [
@@ -950,6 +950,14 @@ Object subclass: SpFilename [
  ^SpTimestamp fromSeconds: entry lastModifyTime
     ]
 
+    name [
+ "a String
+ return the filename identified by self."
+
+ <category: 'initialize-release'>
+ ^filename
+    ]
+
     named: aString [
  "^self
  I initialize myself to represent the filename identified by aString."
@@ -1225,7 +1233,7 @@ Object subclass: SpSocket [
  I return true if a read operation will return some number of bytes."
 
  <category: 'services-io'>
- ^self underlyingSocket canRead
+ ^self underlyingSocket available
     ]
 
     setAddressReuse: aBoolean [
@@ -1252,7 +1260,7 @@ Object subclass: SpSocket [
 
  <category: 'services-io'>
  | bad sem timeout socketWait |
- self underlyingSocket canRead ifTrue: [ ^true ].
+ self underlyingSocket available ifTrue: [ ^true ].
  sem := Semaphore new.
  timeout :=
     [ (Delay forMilliseconds: aNumberOfMilliseconds) wait. sem signal ]
@@ -1263,7 +1271,7 @@ Object subclass: SpSocket [
  [ sem wait ] ensure: [
     timeout terminate.
     socketWait terminate ].
- ^self underlyingSocket canRead
+ ^self underlyingSocket available
     ]
 
     write: sourceByteArray [
@@ -1272,8 +1280,11 @@ Object subclass: SpSocket [
  I return the number of bytes written."
 
  <category: 'services-io'>
+ "TODO: accept bytearrays in sockets."
  ^SpExceptionContext
-    for: [self underlyingSocket nextPutAllFlush: sourceByteArray]
+    for: [self underlyingSocket
+     nextPutAllFlush: sourceByteArray asString.
+ sourceByteArray size]
     on: Error
     do: [:ex | SpSocketError raiseSignal: ex]
     ]
@@ -1283,12 +1294,14 @@ Object subclass: SpSocket [
  I return the number of bytes actually written."
 
  <category: 'services-io'>
+ "TODO: accept bytearrays in sockets."
  ^SpExceptionContext
     for:
  [self underlyingSocket
     next: length
-    putAll: aByteArray
-    startingAt: startIndex; flush]
+    putAll: aByteArray asString
+    startingAt: startIndex; flush.
+ length]
     on: Error
     do: [:ex | SpSocketError raiseSignal: ex]
     ]
diff --git a/packages/tcp/Sockets.st b/packages/tcp/Sockets.st
index aa0bdd2..2cd3efd 100644
--- a/packages/tcp/Sockets.st
+++ b/packages/tcp/Sockets.st
@@ -159,6 +159,13 @@ Stream subclass: AbstractSocket [
  self subclassResponsibility
     ]
 
+    ensureReadable [
+ "Suspend the current process until more data is available on the
+ socket."
+
+ self implementation ensureReadable
+    ]
+
     available [
  "Answer whether there is data available on the socket."
 
@@ -1052,6 +1059,13 @@ AbstractSocket subclass: Socket [
  ^self peek isNil
     ]
 
+    ensureReadable [
+ "Suspend the current process until more data is available in the
+ socket's read buffer or from the operating system."
+
+ self available ifFalse: [ super ensureReadable ]
+    ]
+
     available [
  "Answer whether more data is available in the socket's read buffer
  or from the operating system."

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk