Skip to content

Commit

Permalink
Sync with upstream MC repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Van Caekenberghe committed Jul 14, 2016
1 parent ad0ae54 commit 0116504
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 46 deletions.
Expand Up @@ -5,4 +5,6 @@ close
[ self flush ] ensure: [
socket ifNotNil: [
self socketClose.
socket := nil ] ]
socket := nil ].
readBuffer close.
writeBuffer close ]
@@ -1,3 +1,3 @@
private socket
socketIsConnected
^ socket isConnected
^ socket isConnected and: [ socket isOtherEndClosed not ]
Expand Up @@ -6,7 +6,7 @@
"autoFlush:" : "SvenVanCaekenberghe 11/10/2011 13:06",
"binary" : "SvenVanCaekenberghe 11/10/2011 13:07",
"bufferSize:" : "SvenVanCaekenberghe 11/10/2011 13:08",
"close" : "SvenVanCaekenberghe 6/3/2013 19:45",
"close" : "SvenVanCaekenberghe 5/3/2015 23:21",
"collectionSpecies" : "SvenVanCaekenberghe 5/17/2011 18:52",
"debug:" : "SvenVanCaekenberghe 5/17/2011 18:52",
"fillReadBuffer" : "SvenVanCaekenberghe 5/17/2011 18:52",
Expand Down Expand Up @@ -37,7 +37,7 @@
"socket" : "SvenVanCaekenberghe 5/17/2011 18:52",
"socketClose" : "SvenVanCaekenberghe 5/18/2013 21:26",
"socketConnectTo:port:" : "SvenVanCaekenberghe 5/20/2011 13:04",
"socketIsConnected" : "SvenVanCaekenberghe 3/18/2014 14:19",
"socketIsConnected" : "SvenVanCaekenberghe 5/20/2011 12:58",
"socketIsDataAvailable" : "SvenVanCaekenberghe 5/20/2011 12:59",
"socketReceiveDataInto:startingAt:count:" : "SvenVanCaekenberghe 5/20/2011 12:56",
"socketSendData:startingAt:count:" : "SvenVanCaekenberghe 5/20/2011 13:13",
Expand Down
@@ -1,3 +1,3 @@
instance creation
onByteArrayOfSize: size
^ self on: (ByteArray new: size)
^ self on: (ZdcByteArrayManager current byteArrayOfSize: size zero: true)
Expand Up @@ -2,4 +2,5 @@ accessing
bufferSize
"Return the raw size of the underlying buffer"

buffer ifNil: [ ^ 0 ].
^ buffer size
Expand Up @@ -2,9 +2,12 @@ printing
printOn: stream
super printOn: stream.
stream nextPut: $(.
self gapAtFront > 0
ifTrue: [ stream nextPut: $-; print: self gapAtFront; space ].
stream print: self contents.
self availableForWriting > 0
ifTrue: [ stream space; nextPut: $+; print: self availableForWriting ].
buffer
ifNil: [ stream << 'closed' ]
ifNotNil: [
self gapAtFront > 0
ifTrue: [ stream nextPut: $-; print: self gapAtFront; space ].
stream print: self contents.
self availableForWriting > 0
ifTrue: [ stream space; nextPut: $+; print: self availableForWriting ] ].
stream nextPut: $)
@@ -1,7 +1,7 @@
{
"class" : {
"on:" : "SvenVanCaekenberghe 5/17/2011 18:46",
"onByteArrayOfSize:" : "SvenVanCaekenberghe 5/17/2011 18:46" },
"onByteArrayOfSize:" : "SvenVanCaekenberghe 5/6/2015 21:37" },
"instance" : {
"advanceReadPointer:" : "SvenVanCaekenberghe 5/17/2011 18:46",
"advanceWritePointer:" : "SvenVanCaekenberghe 5/17/2011 18:46",
Expand All @@ -10,8 +10,9 @@
"buffer" : "SvenVanCaekenberghe 5/17/2011 18:46",
"bufferEmptyError" : "SvenVanCaekenberghe 5/17/2011 18:46",
"bufferFullError" : "SvenVanCaekenberghe 5/17/2011 18:46",
"bufferSize" : "SvenVanCaekenberghe 5/17/2011 18:46",
"bufferSize" : "SvenVanCaekenberghe 5/3/2015 23:39",
"capacity" : "SvenVanCaekenberghe 5/17/2011 18:46",
"close" : "SvenVanCaekenberghe 5/6/2015 21:37",
"compact" : "SvenVanCaekenberghe 5/17/2011 18:46",
"contents" : "SvenVanCaekenberghe 5/17/2011 18:46",
"contentsEnd" : "SvenVanCaekenberghe 5/17/2011 18:46",
Expand All @@ -26,7 +27,7 @@
"nextPut:" : "SvenVanCaekenberghe 5/17/2011 18:46",
"on:" : "SvenVanCaekenberghe 5/17/2011 18:46",
"peek" : "SvenVanCaekenberghe 5/19/2011 12:50",
"printOn:" : "SvenVanCaekenberghe 5/17/2011 18:46",
"printOn:" : "SvenVanCaekenberghe 5/3/2015 23:33",
"readInto:startingAt:count:" : "SvenVanCaekenberghe 5/28/2013 15:48",
"reset" : "SvenVanCaekenberghe 5/17/2011 18:46",
"size" : "SvenVanCaekenberghe 5/17/2011 18:46" } }
Expand Up @@ -6,4 +6,5 @@ initialize
on: PrimitiveFailed
do: [ :exception |
"Give a more human friendly error message"
ZdcPluginMissing signal ]
ZdcPluginMissing signal ].
self logging: false
@@ -1,7 +1,7 @@
primitives
primitiveSSL: sslHandle setIntProperty: propID toValue: anInteger
"Primitive. Sets a string property in an SSL session"
"Primitive. Sets an integer property in an SSL session"

<primitive: 'primitiveSetStringProperty' module: 'SqueakSSL'>
<primitive: 'primitiveSetIntProperty' module: 'SqueakSSL'>

^ self primitiveFailed
Expand Up @@ -7,11 +7,15 @@
"certificateName:" : "SvenVanCaekenberghe 5/18/2011 10:01",
"certificateVerificationState" : "SvenVanCaekenberghe 5/18/2011 10:01",
"connect:from:to:into:" : "SvenVanCaekenberghe 5/18/2011 10:01",
"constantsSQSSL_PROP_LOGLEVEL" : "KrisGybels 10/24/2014 12:31",
"decrypt:from:to:into:" : "SvenVanCaekenberghe 12/6/2011 11:32",
"destroy" : "SvenVanCaekenberghe 5/18/2011 10:01",
"enableLogging" : "SvenVanCaekenberghe 10/24/2014 13:54",
"encrypt:from:to:into:" : "SvenVanCaekenberghe 12/6/2011 11:32",
"initialize" : "SvenVanCaekenberghe 6/28/2012 09:27",
"initialize" : "SvenVanCaekenberghe 10/24/2014 13:50",
"isConnected" : "SvenVanCaekenberghe 5/18/2011 10:01",
"logging" : "KrisGybels 10/24/2014 12:32",
"logging:" : "KrisGybels 10/24/2014 12:32",
"peerCertificateName" : "SvenVanCaekenberghe 5/18/2011 10:01",
"pluginVersion" : "SvenVanCaekenberghe 5/18/2011 10:01",
"primitiveSSL:accept:startingAt:count:into:" : "SvenVanCaekenberghe 5/18/2011 10:01",
Expand All @@ -20,7 +24,7 @@
"primitiveSSL:encrypt:startingAt:count:into:" : "SvenVanCaekenberghe 5/18/2011 10:01",
"primitiveSSL:getIntProperty:" : "SvenVanCaekenberghe 5/18/2011 10:01",
"primitiveSSL:getStringProperty:" : "SvenVanCaekenberghe 5/18/2011 10:01",
"primitiveSSL:setIntProperty:toValue:" : "SvenVanCaekenberghe 5/18/2011 10:01",
"primitiveSSL:setIntProperty:toValue:" : "KrisGybels 10/24/2014 12:32",
"primitiveSSL:setStringProperty:toValue:" : "SvenVanCaekenberghe 5/18/2011 10:01",
"primitiveSSLCreate" : "SvenVanCaekenberghe 5/18/2011 10:01",
"primitiveSSLDestroy:" : "SvenVanCaekenberghe 5/18/2011 10:01",
Expand Down
Expand Up @@ -6,4 +6,6 @@ close
[ super close ] ensure: [
sslSession ifNotNil: [
sslSession destroy.
sslSession := nil ] ]
sslSession := nil ].
ZdcByteArrayManager current recycle: in; recycle: out.
in := out := nil ]
Expand Up @@ -3,17 +3,23 @@ fillBytes: bytes startingAt: offset count: count
"Ask to read count elements into bytes starting at offset. Do not wait. Return read count.
Overwritten: decrypt and if necessary ask the socket for encrypted data using a super call."

| processedCount processData inCount |
processData := [
processedCount < 0 ifTrue: [ ^ self sslException: 'decrypt failed' code: processedCount ].
processedCount > 0
ifTrue: [
bytes replaceFrom: offset to: offset + processedCount - 1 with: out startingAt: 1.
^ processedCount ] ].
| processedCount inCount |
self resetEncryptedBuffers.
processedCount := self sslSession decrypt: in from: 1 to: 0 into: out.
processData value.
"The SSL session might contain left over state, get it"
processedCount := self sslSession decrypt: in from: 1 to: 0 into: out.
"We explicitly ignore possible errors here"
processedCount > 0
ifTrue: [
bytes replaceFrom: offset to: offset + processedCount - 1 with: out startingAt: 1.
^ processedCount ].
"Now, get new encrypted bytes and decrypt if needed"
inCount := self fillEncryptedBytes: in startingAt: 1 count: in size.
processedCount := self sslSession decrypt: in from: 1 to: inCount into: out.
processData value.
inCount > 0
ifTrue: [
processedCount := self sslSession decrypt: in from: 1 to: inCount into: out.
"We explicitly ignore possible errors here"
processedCount > 0
ifTrue: [
bytes replaceFrom: offset to: offset + processedCount - 1 with: out startingAt: 1.
^ processedCount ] ].
^ 0
Expand Up @@ -4,7 +4,7 @@ flushBytes: bytes startingAt: offset count: count
Overwritten: first encrypt the data, then send it to the socket using a super call."

| remaining currentOffset |
socket ifNil: [ ConnectionClosed signal: 'Cannot write data' ].
self isConnected ifFalse: [ ConnectionClosed signal: 'Cannot write data' ].
remaining := count.
currentOffset := offset.
[ remaining > 0 ] whileTrue: [ | chunkCount writeCount |
Expand Down
Expand Up @@ -5,5 +5,5 @@ initializeBuffers

readBuffer := ZdcIOBuffer onByteArrayOfSize: 16 * 1024.
writeBuffer := ZdcIOBuffer onByteArrayOfSize: 4 * 1024.
in := ByteArray new: 4096.
out := ByteArray new: (16 + 1) * 1024
in := ZdcByteArrayManager current byteArrayOfSize: 4096 zero: false.
out := ZdcByteArrayManager current byteArrayOfSize: (16 + 1) * 1024 zero: false
Expand Up @@ -4,14 +4,14 @@
"instance" : {
"accept" : "SvenVanCaekenberghe 7/12/2012 15:10",
"atEnd" : "SvenVanCaekenberghe 7/12/2012 23:08",
"close" : "SvenVanCaekenberghe 6/3/2013 19:46",
"close" : "SvenVanCaekenberghe 5/6/2015 21:37",
"connect" : "SvenVanCaekenberghe 7/12/2012 15:10",
"fillBytes:startingAt:count:" : "SvenVanCaekenberghe 7/12/2012 23:01",
"fillBytes:startingAt:count:" : "SvenVanCaekenberghe 3/5/2015 22:29",
"fillEncryptedBytes:startingAt:count:" : "SvenVanCaekenberghe 7/12/2012 15:02",
"flushBytes:startingAt:count:" : "SvenVanCaekenberghe 3/18/2014 14:28",
"flushBytes:startingAt:count:" : "SvenVanCaekenberghe 7/12/2012 15:01",
"flushEncryptedBytes:startingAt:count:" : "SvenVanCaekenberghe 7/12/2012 14:57",
"initialize" : "SvenVanCaekenberghe 5/18/2011 16:00",
"initializeBuffers" : "SvenVanCaekenberghe 8/23/2012 11:21",
"initializeBuffers" : "SvenVanCaekenberghe 5/6/2015 21:37",
"isConnected" : "SvenVanCaekenberghe 5/18/2011 11:49",
"isDataAvailable" : "SvenVanCaekenberghe 8/23/2012 11:26",
"readEncryptedBytes:startingAt:count:" : "SvenVanCaekenberghe 7/12/2012 15:09",
Expand Down
Expand Up @@ -2,7 +2,6 @@ private in
fillBytes: bytes startingAt: offset count: count
"Ask the socket to read count elements into bytes starting at offset. Do not wait. Return read count."

count = 0 ifTrue: [ ^ 0 ].
self isConnected ifFalse: [ ConnectionClosed signal: 'Cannot read data' ].
^ self
socketReceiveDataInto: bytes
Expand Down
Expand Up @@ -5,5 +5,5 @@ fillReadBuffer
self fillReadBufferNoWait.
(readBuffer isEmpty and: [ self isConnected ])
ifTrue: [
self socketWaitForData. "when successful, recurse, else signal exception"
[ self socketWaitForData ] on: ConnectionClosed do: [ ^ self ]. "when successful, recurse, else signal exception"
self fillReadBuffer ]
Expand Up @@ -3,8 +3,7 @@ flushBytes: bytes startingAt: offset count: count
"Ask the socket to write count bytes starting from offset. Wait. Fail if not successful"

| writeCount |
count = 0 ifTrue: [ self ].
socket ifNil: [ ConnectionClosed signal: 'Cannot write data' ].
self isConnected ifFalse: [ ConnectionClosed signal: 'Cannot write data' ].
writeCount := 0.
[ | written |
written := self socketSendData: bytes startingAt: offset + writeCount count: count - writeCount.
Expand Down
Expand Up @@ -6,10 +6,10 @@
"instance" : {
"atEnd" : "SvenVanCaekenberghe 7/12/2012 16:25",
"connectTo:port:" : "SvenVanCaekenberghe 5/20/2011 13:07",
"fillBytes:startingAt:count:" : "SvenVanCaekenberghe 3/18/2014 20:27",
"fillReadBuffer" : "SvenVanCaekenberghe 5/20/2011 13:05",
"fillBytes:startingAt:count:" : "SvenVanCaekenberghe 5/20/2011 14:21",
"fillReadBuffer" : "SvenVanCaekenberghe 3/5/2015 22:21",
"fillReadBufferNoWait" : "SvenVanCaekenberghe 5/17/2011 18:52",
"flushBytes:startingAt:count:" : "SvenVanCaekenberghe 3/18/2014 20:27",
"flushBytes:startingAt:count:" : "SvenVanCaekenberghe 5/20/2011 13:05",
"flushWriteBuffer" : "SvenVanCaekenberghe 5/17/2011 18:52",
"isConnected" : "SvenVanCaekenberghe 5/20/2011 13:02",
"isDataAvailable" : "SvenVanCaekenberghe 8/23/2012 11:17" } }

0 comments on commit 0116504

Please sign in to comment.