Jim Dovey
c8ee463a06
Makes sure that the temporary socket opened in Socket.connect(to:port:timeout:) is closed in the event of an error being thrown.
...
I've added two pieces here: first is a `defer` block right after the creation of the `socketDescriptor` variable. If it's non-nil and not `Socket.SOCKET_INVALID_DESCRIPTOR` then the socket is closed pronto. Secondly, I'm explicitly setting this variable to `nil` when it's copied into `self.socketfd`. From that point on, any failure or error thrown will not result in the socket being orphaned, since it's referenced by the `Socket` class instance, and will be cleaned up in its `deinit` implementation.
2018-02-22 13:08:31 -08:00
Jim Dovey
74bbadbc7a
Fixed a bit-addressing error in fd_set implementation.
...
- Now uses an unsigned type to perform the bit-shift operation and then casts to signed type using `init(bitPattern:)`.
- Added a unit test case which ensures fd values from zero to (arbitrarily) 128 can all be inserted and removed from the fd_set.
2018-02-22 12:42:08 -08:00
Bill Abt
f49d9dabdb
Changed to use new SSLError initializer that was changed to accommodate changes in Swift 4.1.
2018-02-21 10:50:39 -05:00
Bill Abt
9979951ee3
Changed name of SSLError.code to SSLError.errCode to avoid clash with Swift.Error._code that was flagged as a warning in Swift 4.1.
2018-02-21 10:49:36 -05:00
Bill Abt
8f31fff919
Merge pull request #121 from IBM-Swift/issue.swift41
...
Update to support Swift 4.1
2018-02-21 10:19:22 -05:00
ShihabMehboob
fd15ef5d44
Squashed commit of the following:
...
commit d658dc3618946a6d295f1604fb8a8378d8d3f1f6
Author: ShihabMehboob <shihab.mehboob1@ibm.com >
Date: Wed Feb 14 13:18:31 2018 +0000
Updates to Swift 4.1
commit fc48ea6a203914081a060424d79af89a96578c7b
Author: ShihabMehboob <shihab.mehboob1@ibm.com >
Date: Wed Feb 14 13:14:17 2018 +0000
Updates to Swift 4.1
commit 3f2c276c247aa4d97a52a65eae0804fa3028261b
Author: ShihabMehboob <shihab.mehboob1@ibm.com >
Date: Wed Feb 14 13:13:56 2018 +0000
Updates to Swift 4.1
commit 664e5ce38c679498a8f35a7adbc22beb70cd08b4
Author: ShihabMehboob <shihab.mehboob1@ibm.com >
Date: Wed Feb 14 13:11:01 2018 +0000
Updates to Swift 4.1
commit 985ea641cbbb1cc7d37a8aa1a19ca019221f0b81
Author: ShihabMehboob <shihab.mehboob1@ibm.com >
Date: Wed Feb 14 12:52:38 2018 +0000
Updates to Swift 4.1
commit 1f74bb681948aca741c3dec025f73aa341efef0f
Author: ShihabMehboob <shihab.mehboob1@ibm.com >
Date: Mon Feb 12 10:27:00 2018 +0000
Support Swift 4.1
commit c86c534b84fb0fcee04030ae948650ab3f5e78df
Author: ShihabMehboob <shihab.mehboob1@ibm.com >
Date: Thu Feb 8 13:59:20 2018 +0000
Support Swift 4.1
2018-02-14 13:20:55 +00:00
Bill Abt
c8c1a1e9c1
Throw an exception if connect is called on a non-blocking socket without a timeout being passed. Updated documentation to reflect this.
2018-02-13 11:22:34 -05:00
Bill Abt
5c07437ab5
Added documentation for public functions. Minor format changes for consistency.
2018-01-27 08:57:26 -05:00
Jim Dovey
fec7cf7438
Fixed the bug in the new fd_set implementation on macOS.
2018-01-26 16:49:44 -08:00
Bill Abt
d3c5ff3ecd
Rollback the fd_set extension changes from PR #107 to the original. The changes were causing a crash bug whenever the new fd_set extensions were called.
2018-01-22 10:32:30 -05:00
Bill Abt
c2cdc36148
Renamed disableSIGPIPE function to ignoreSIGPIPE since that's just a bit more descriptive. Other minor style changes for consistency.
2018-01-19 09:22:22 -05:00
Bill Abt
45da6eb972
Minor style changes.
2018-01-19 09:21:06 -05:00
Jim Dovey
171c7570d7
A few cleanups and one bug fix:
...
- `fd_set` API is now much nicer and will compile about as close to the C implementation as we can get— especially on release builds, with compiler inlining.
- Socket structure's `readBuffer` now initializes all its bytes to zero, not just the first.
- More idiomatic/concise return expression in `Socket.wait(for:timeout:waitForever:)` (don't build an output array manually, we have `filter(_:)` for that).
- Various non-Linux code to set the `SO_NOSIGPIPE` option has been tucked into a private function now, still containing the compilation conditional. It's a no-op on Linux, and will be inlined by the compiler (since it's private) and the calling code looks much more straightforward.
- BUGFIX: calls to `gai_strerror(_:)` take the result of the `getaddrinfo()` call as a parameter, NOT `errno`.
2018-01-16 12:53:27 -08:00
Bill Abt
f9a7368c84
Minor fix in datagram handling when a datagram read is interrupted.
2017-12-14 09:13:11 -05:00
Bill Abt
dc44869fc4
Added missing documentation for allowPortReuse on the listen() API. Part of issue #94 .
2017-10-26 17:57:38 -04:00
Bill Abt
fb0c9c1e87
Introduced OperationInterrupted exception to replace NotAnError that was included in PR #93 . This makes things clearer. Also, made the new exception part of Socket to avoid redundant declarations.
2017-10-26 10:03:19 -04:00
Bill Abt
abfe351df1
Added missing documentation for new Socket.Address extensions introduced by PR #93 .
2017-10-26 10:00:02 -04:00
Bill Abt
eaddb730d8
Merge pull request #93 from mcfedr/fix-unsafe-socket
...
Remove unsafe access to Socket.Address. Some modifications needed prior to release.
2017-10-26 09:24:27 -04:00
Bill Abt
badbf15cb8
Add new parameter for listen() API that allows the caller to decide whether to reuse the listening port or not. Default behavior is to reuse the port.
2017-10-12 10:30:12 -04:00
Fred Cox
2d58a7a264
Remove unsafe access to Socket.Address
...
asAddr funcs were passing unsafe pointers outside of the callbacks in which try should be used
Using callback to make all the access within these callbacks
Fixes bug where IPv6 address was 'cast' to sockaddr but actually was zero'd beyond the length of sockaddr_in and packets written to the wrong address
2017-10-12 10:51:40 +03:00
Bill Abt
60cf41bcc4
Simplify parameter checking in wait() API.
2017-10-11 09:49:45 -04:00
Bill Abt
5aae4f88a4
Fix logic error in wait() function introduced in previous check-in that allows wait() to be called on UDP socket.
2017-10-09 12:22:44 -04:00
Bill Abt
389bd17eab
Allow wait() to be called for UDP sockets that are bound.
2017-10-06 09:46:28 -04:00
Bill Abt
51bde30c86
Update FD_* functions to consistently use Int32 where appropriate.
2017-10-06 09:45:05 -04:00
Bill Abt
1c957b4272
When connecting to a socket, we replace the existing socket with a newly generated one. On macOS, need to set SO_NOSIGPIPE on the new socket.
2017-09-28 09:03:17 -04:00
Bill Abt
a985882a9f
Posix/BSD/Darwin sockets are not supported by watchOS on native devices. Therefore, removed package/compilation support for that platform.
2017-09-21 10:54:24 -04:00
Bill Abt
ddd0be6008
If there's a delegate present, ALWAYS set the needAcceptDelegateCall flag otherwise, the default case won't work.
2017-09-14 12:17:03 -04:00
Bill Abt
5c77668e31
Added new parameter to acceptClientConnection that allows deferral of SSL accept to the application. Added new function, invokeDelegateOnAccept, to invoke the SSL accept. Modification of PR #85 .
2017-09-14 11:23:32 -04:00
David Jones
01626cd32f
IBM-Swift/Kitura#1143 IBM-Swift/BlueSSLService#40 Enable decoupling of acceptClientConnection and delegate.onAccept
2017-09-14 13:32:20 +01:00
Quan Vo
558fdeb7b6
Swift 4 support
2017-08-23 11:36:57 -05:00
Bill Abt
19163ec97e
In the connect API, If the socket is in blocking mode it will be changed to non-blocking mode temporarily if a timeout greater than zero (0) is provided. The returned socket will be set back to its original setting (blocking or non-blocking). This obviates the need to set the socket into non-blocking mode in order to utilize the connection timeout.
2017-08-06 10:15:17 -04:00
Bill Abt
40db185c15
Added new parameter to connect API to allow the setting of a timeout value when using non-blocking sockets.
2017-08-05 11:10:14 -04:00
Bill Abt
fb557515d1
Fixed problem with interpreting the passed boolean value. Was disabling broadcast instead of enabling it and vice versa due to an error coding the ternary.
2017-08-03 15:48:55 -04:00
Bill Abt
1e825b58fa
Added new utility function, udpBroadcast, to allow enablement and disablement of broadcast mode fro UDP sockets.
2017-08-03 11:58:41 -04:00
Bill Abt
632e6cd9ed
If the attempt to set the SO_REUSEPORT socket option fails, check errno for ENOPROTOOPT and if set, silently ignore the error. This can happen when using WSL (Windows Subsystem for Linux).
2017-08-01 11:38:17 -04:00
Bill Abt
52ae8858c9
Fixed some minor swiftlint warnings.
2017-06-21 20:20:20 -04:00
Martin Angers
a661bc2dad
fix formatting
2017-06-21 14:50:38 -04:00
Martin Angers
52a1d88d4e
remove need to force-unwrap path
2017-06-21 14:34:47 -04:00
Martin Angers
776c421c06
replace strncpy with UnsafeMutableBufferPointer
2017-06-21 14:33:15 -04:00
Yossi Mesika
74b5335331
Added missing parameter description and build only on linux
2017-06-09 06:55:23 +03:00
Yossi Mesika
1418e63280
Merge remote-tracking branch 'IBM-Swift/master'
2017-05-23 16:27:47 +03:00
Yossi Mesika
659cfee17c
Changed indentation from spaces to tabs as used throughout the code
2017-05-23 16:15:59 +03:00
Yossi Mesika
091eb32e02
Updated SSLServiceDelegate with a function and field to support ALPN and HTTP/2
2017-05-22 21:16:39 +03:00
Bill Abt
3c06c5a5bb
During a read operation with truncate equal to true, the memcpy statement was incorrect, causing a buffer overflow. This commit corrects that problem.
2017-05-19 09:18:33 -04:00
Quan Vo
a8f5d40ef8
Cast mask to Int32
2017-05-12 16:24:29 -05:00
Bouke Haarsma
e639a3fd5e
Set SO_REUSEPORT for port sharing on OSX
2017-03-30 22:15:07 +02:00
Bill Abt
0986c40a4d
Port check range for connect should've been 1-65535 not 1024-65535..
2017-03-27 12:53:28 -04:00
Bill Abt
c9ff50a4fa
Validate the port values passed to connect(to:port:) function and ensure they fall within the proper range.
2017-03-27 12:44:34 -04:00
Bill Abt
6033ce5bae
Reduce the default SSL read buffer size.
2017-03-24 16:06:51 -04:00
Bill Abt
b7e428d75f
When the SSLServiceDelegate is set to a non-nil value, increase the read buffer size to accommodate the TLS packet size.
2017-03-24 10:49:51 -04:00