0001 // TCPServerSocket.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 import CLibvenice 0026 @_exported import IP 0027 0028 public final class TCPServerSocket: TCPSocket { 0029 public init(ip: IP, backlog: Int = 128, reusePort: Bool = false) throws { 0030 try super.init(socket: tcplisten(ip.address, Int32(backlog), reusePort ? 1 : 0)) 0031 } 0032 0033 public init
TCPStreamServer.swift:28 let serverSocket: TCPServerSocketTCPStreamServer.swift:34 self.serverSocket = try TCPServerSocket(ip: ip, backlog: backlog, reusePort: reusePort)(fileDescriptor: FileDescriptor) throws { 0034 try super.init(socket: tcpattach(fileDescriptor, 1)) 0035 } 0036 0037 public func accept(deadline: Deadline = never) throws -> TCPClientSocket { 0038 try assertNotClosed() 0039 return try TCPClientSocket(socket: tcpaccept(socket, deadline)) 0040 } 0041 0042 public func attach(fileDescriptor: FileDescriptor) throws { 0043 try super.attach(fileDescriptor, isServer: true) 0044 } 0045 }
TCPServerSocket.swift:29 public init(ip: IP, backlog: Int = 128, reusePort: Bool = false) throws {