Last active
April 22, 2016 14:37
-
-
Save ketzusaka/e0877d827964930e5ccd2b0f75de9a0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Current HTTPStream: | |
| protocol HTTPStream: Stream { | |
| static func makeStream() -> Self | |
| func bind(to ip: String?, on port: Int) throws | |
| func accept(max connectionCount: Int, handler: (HTTPStream -> Void)) throws | |
| func listen() throws | |
| func receiveByte() throws -> Byte? | |
| func receiveLine() throws -> String | |
| func sendHeaderEndOfLine() throws | |
| func send(headerLine line: String) throws | |
| func send(headerKey key: String, headerValue value: String) throws | |
| func send(_ string: String) throws | |
| func receive() throws -> HTTPStreamHeader | |
| func receive() throws -> Request | |
| func send(_ response: Response, keepAlive: Bool) throws | |
| func send(_ body: Response.Body) throws | |
| } | |
| // New HTTPStream: | |
| protocol HTTPStream: Stream { | |
| func receiveByte() throws -> Byte? | |
| func receiveLine() throws -> String | |
| func sendHeaderEndOfLine() throws | |
| func send(headerLine line: String) throws | |
| func send(headerKey key: String, headerValue value: String) throws | |
| func send(_ string: String) throws | |
| func receive() throws -> HTTPStreamHeader | |
| func receive() throws -> Request | |
| func send(_ response: Response, keepAlive: Bool) throws | |
| func send(_ body: Response.Body) throws | |
| } | |
| // New protocol that is used by the HTTPStreamServer: | |
| protocol HTTPListenerStream: HTTPStream { | |
| init(address: String?, port: Int) throws // ip and port here vs bind to mirror S4; this replaces makeStream() | |
| func bind() throws | |
| func accept(max connectionCount: Int, handler: (HTTPStream -> Void)) throws | |
| } | |
| With the above, Hummingbird.Socket would conform to HTTPStream, and a new Hummingbird.ServerSocket would conform to HTTPListenerStream |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment