tcl-hacks

Check-in [1adc0b6492]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:minhttpd: remove colliding close method, avoid port contention and print url on startup
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1adc0b6492dc19fc6d9ead63f1cbc3fa1e79403e
User & Date: aspect 2019-03-01 14:25:55
Context
2019-03-02
13:06
install hack for starpacks to use modules check-in: 601b5ddac7 user: aspect tags: trunk
2019-03-01
14:25
minhttpd: remove colliding close method, avoid port contention and print url on startup check-in: 1adc0b6492 user: aspect tags: trunk
2018-12-11
07:07
merge tclish-args, which includes commits unrelated to its topic check-in: 0227bf5899 user: aspect tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/minhttpd-0.tm.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
163
164
165
166
167
168
169



170








171
172
173
174
175
176
177
        if {[regexp {(.*):(.*)} $port -> host port]} {
            dict set sockargs -myaddr $host
        }
        set listenfd [socket {*}$sockargs $port]
        return $listenfd
    }

    proc close {listenfd} {
        close $listenfd
        # timeouts will take care of existing clients
    }

    proc accept {callback chan caddr cport} {
        coroutine coro#$chan#[info cmdcount] Accept $callback $chan
    }
................................................................................
            return -code $rc {*}$opts $res
        }
    }
}

if {[info script] eq $::argv0} {




    set svrfd [minhttpd::serve httpGet 8080]









    proc httpGet {url} {
        if {$url eq "/"} {
            return -code 302 /index.html
        }
        if {$url eq "/admin"} {
            return -code 403 "You are not allowed!"







|







 







>
>
>
|
>
>
>
>
>
>
>
>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
        if {[regexp {(.*):(.*)} $port -> host port]} {
            dict set sockargs -myaddr $host
        }
        set listenfd [socket {*}$sockargs $port]
        return $listenfd
    }

    proc stop {listenfd} {
        close $listenfd
        # timeouts will take care of existing clients
    }

    proc accept {callback chan caddr cport} {
        coroutine coro#$chan#[info cmdcount] Accept $callback $chan
    }
................................................................................
            return -code $rc {*}$opts $res
        }
    }
}

if {[info script] eq $::argv0} {

    set port 8080
    while {$port < 8100} {
        try {
            set svrfd [minhttpd::serve httpGet $port]
            puts "Listening on http://localhost:$port/"
            break
        } on error {} continue
    }
    if {![info exists svrfd]} {
        puts "Unable to open server socket!"
        exit 1
    }

    proc httpGet {url} {
        if {$url eq "/"} {
            return -code 302 /index.html
        }
        if {$url eq "/admin"} {
            return -code 403 "You are not allowed!"