Giter VIP home page Giter VIP logo

Comments (8)

damian-kolakowski avatar damian-kolakowski commented on May 4, 2024

I've just tested it using demo iOS app and works fine for me. Anyway, could you please paste the code you use for testing ?

from swifter.

RGreinacher avatar RGreinacher commented on May 4, 2024

Sorry for the late answer; I can reproduce the mentioned behavior with the following sample code:
I figured out, that the server doesn't shut down only if there was a request before the server.stop() method is called. If you just start it and wait until stop() is called without performing a request, the server will behave as expected; the request will be refused.

Run the following twice, once just wait until the sleep(5) is over and then try to request the server, and once fire a request within the time of the sleep(5) (like http://localhost:9080) and try the same after stop() was called. The latter will answer twice (or more, it just seems to not release the socket).

import Foundation
var error: NSError?
let server = demoServer(NSBundle.mainBundle().resourcePath)

if !server.start(listenPort: 9080, error: &error) {
        println("Server start error: \(error)")
} else {
        println("Server started; try a connection now")
        sleep(5)

        println("main thread is awake again")
        server.stop()

        println("stopped server; try to connect")
        while ( true ) { };
}

from swifter.

damian-kolakowski avatar damian-kolakowski commented on May 4, 2024

ok. Thanks. I can reproduce it.

from swifter.

damian-kolakowski avatar damian-kolakowski commented on May 4, 2024

The problem is a while loop happening in case of "keep-alive" session.

from swifter.

RGreinacher avatar RGreinacher commented on May 4, 2024

I see. What do you think of a force-kill-switch like server.sleep(forceShutdown: Bool)?

from swifter.

damian-kolakowski avatar damian-kolakowski commented on May 4, 2024

I would like to extend server::stop() by closing all sockets.

from swifter.

damian-kolakowski avatar damian-kolakowski commented on May 4, 2024

This solves the problem:

b37392b

from swifter.

RGreinacher avatar RGreinacher commented on May 4, 2024

Great work! Thank you! :)

from swifter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.