Commit b01f1925 authored by James Hughes's avatar James Hughes
Browse files

updated socket. Now uses a String for the port number and DNS resolution for the host name.

parent 37a50b94
Loading
Loading
Loading
Loading
+4 −44
Original line number Diff line number Diff line
@@ -18,43 +18,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// @author: Ignacio Corderi
// @author: Ignacio Corderi :-P


//import BrightFutures

public let connect = NetworkChannel.connect
public func connect(host: String, port: Int = NetworkChannel.DEFAULT_PORT, timeout: Double = 1.0) throws ->  KineticSession {
    print (1)
public func connect(host: String, port: Int = NetworkChannel.DEFAULT_PORT, timeout: Double = NetworkChannel.DEFAULT_CONNECT_TIMEOUT) throws ->  KineticSession {
    return try NetworkChannel.connect(host, port: port, timeout: timeout)
}

//extension NSInputStream {
//    
//    func read(fully length: Int) -> Bytes {
//        var buffer = Bytes(count:length, repeatedValue: 0)
//        // TODO: loop until you read it all
//        let _ = self.read(&buffer, maxLength: length)
//        return buffer
//    }
//    
//}
//
//extension NSOutputStream {
//    
//    func write(bytes: Bytes) -> Int {
//        return self.write(bytes, maxLength: bytes.count)
//    }
//    
//}
//
//extension NSStream {
//    public var isOpen : Bool {
//        return self.streamStatus == .Open ||
//            self.streamStatus == .Writing ||
//            self.streamStatus == .Reading
//    }
//}

import Socket


@@ -82,12 +54,10 @@ public class NetworkChannel: CustomStringConvertible, KineticChannel {
    internal init(host:String, port:Int, timeout: Double = NetworkChannel.DEFAULT_CONNECT_TIMEOUT) throws {
        self.port = port
        self.host = host
        print(3)
        stream = try Stream(connectTo: host, port: in_port_t(port), timeout: timeout)
        stream = try Stream(connectTo: host, port: String(port), timeout: timeout)
    }
    
    public static func connect(host: String, port: Int, timeout: Double = NetworkChannel.DEFAULT_CONNECT_TIMEOUT) throws -> KineticSession {
        print(2)
        let c = try NetworkChannel(host: host, port: port, timeout: timeout)

        let s = KineticSession(channel: c)
@@ -127,13 +97,3 @@ public class NetworkChannel: CustomStringConvertible, KineticChannel {
        return try encoding.decode()
    }
}

//extension NetworkChannel: CustomReflectable {
//    public func customMirror() -> Mirror {
//        return Mirror(self, children: [
//            "host" : self.host,
//            "port" : self.port,
//            "connected" : self.connected,
//            ])
//    }
//}
 No newline at end of file
+7 −1
Original line number Diff line number Diff line
@@ -11,9 +11,15 @@ import XCTest

class KineticTests: XCTestCase {
    
    var c: KineticSession? = nil
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
        do {
            c = try Kinetic.connect("127.0.0.1")
        } catch let x {
            XCTFail(String(x))
        }
    }
    
    override func tearDown() {
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ CHECKOUT OPTIONS:
    :commit: ad4db3095a9ccc034c1eb65934a89c670012e6a0
    :git: https://github.com/krzyzanowskim/CryptoSwift
  Socket:
    :commit: b63d23e3f8dd8353c8d8514fb8e6d859c79dce17
    :commit: ece06de15752c013e14d15d9e5c1aeefc70b1ea7
    :git: https://github.com/jphughes/socket-swift

SPEC CHECKSUMS:
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ CHECKOUT OPTIONS:
    :commit: ad4db3095a9ccc034c1eb65934a89c670012e6a0
    :git: https://github.com/krzyzanowskim/CryptoSwift
  Socket:
    :commit: b63d23e3f8dd8353c8d8514fb8e6d859c79dce17
    :commit: ece06de15752c013e14d15d9e5c1aeefc70b1ea7
    :git: https://github.com/jphughes/socket-swift

SPEC CHECKSUMS:
+359 −359

File changed.

Preview size limit exceeded, changes collapsed.

Loading