Skip to content

Commit

Permalink
changed connection process behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Gagnant committed Sep 25, 2016
1 parent a701370 commit b975470
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Binary file not shown.
24 changes: 17 additions & 7 deletions Socket/TCPSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class TCPSocket {

public var delegate: TCPSocketDelegate?
public var status: Status
public var host: String
public var port: Int

fileprivate var outputStreamDelegate: StreamDelegate?
fileprivate var inputStreamDelegate: StreamDelegate?
Expand All @@ -32,26 +34,36 @@ public class TCPSocket {
fileprivate var runLoop: RunLoop?
fileprivate var options: Settings

public init(delegate: TCPSocketDelegate? = nil) {
public init(host: String, port: Int) {

options = [
SocketSecurityLevel:SocketSecurityLevelNegotiated as AnyObject,
SocketValidatesCertificateChain:true as AnyObject
]

self.runLoop = nil
self.delegate = nil
self.status = .closed
self.delegate = delegate
self.port = port
self.host = host

inputStreamDelegate = StreamDelegate(cInputStream )
outputStreamDelegate = StreamDelegate(cOutputStream)
}

public convenience init(host: String, port: Int, settings: Settings) {
self.init(host: host, port: port)

settings.forEach { (key, value) in
options[key] = value
}
}

deinit {
disconnect()
}

open func connect(_ host: String, port: Int, settings: Settings = Settings()) {
open func connect() {

if self.status != .closed {
self.disconnect()
Expand All @@ -65,7 +77,7 @@ public class TCPSocket {
inputStream! .delegate = inputStreamDelegate
outputStream!.delegate = outputStreamDelegate

self.parseSettings(settings)
self.parseSettings()

queue.async {

Expand Down Expand Up @@ -152,9 +164,7 @@ public class TCPSocket {
}
}

fileprivate func parseSettings(_ settings: Settings) {

settings.forEach({ options[$0] = $1 })
fileprivate func parseSettings() {

if options[SocketSecurityLevel] as? String == SocketSecurityLevelNegotiated {

Expand Down

0 comments on commit b975470

Please sign in to comment.