kdwatch 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/kdwatch +34 -2
  3. data/lib/kdwatch/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50e6ea6a1e81ab7f17173c1251395a6fbeb1a4b4c236d1c9c6fd1731f3118ca8
4
- data.tar.gz: 31235eb66b35d5c39ebd1f124e938dfcc9b3f305a020ddf05dc610b7e8832707
3
+ metadata.gz: 2e2ba541b81a0758e14930c2daeeb13f8795ef86f13db41d2099ba2c863ae6a8
4
+ data.tar.gz: 225edec007a3005fb9e401888073d3e74fd6d92db622560685d812d0a37527ea
5
5
  SHA512:
6
- metadata.gz: 39e2d6062ef4adf87ce11d05c2d18e4d305de91e8212d1c204bc7bd0b8c8086f3c662e59deeaa284779f326bebdbd3c06af6ec993c4bc3ad4ad0dea0a468ee80
7
- data.tar.gz: 9db4d837a11aea7413de4362bc418cb56fb2f987dc926ab722bd1b8be06850a2a2e51110e78dd75caebec5b2b7280e0b14592910f00478879b127e8724d0b070
6
+ metadata.gz: 7f61fd99900cb3e4b1951863424816438e7e426b84c3cc0e4854f4a64954f26e2ec56f13b08394d4c086fe2d9b919cd4fa66ed4486ef10daebace7d30767c0b1
7
+ data.tar.gz: 4c0853a737166b50b728d6ecbd29845c908fa5e1fcc4b07ea88bbd762c3b6f71b281a7429acbc07f452e3a1a6e9e18f29d7198b97e6d96edef98bbdaef8aa6ad
data/bin/kdwatch CHANGED
@@ -6,11 +6,24 @@ ENV["KRAMDOWN_PERSISTENT"]="yes"
6
6
 
7
7
  require 'optparse'
8
8
  require 'ostruct'
9
+ require 'socket'
9
10
 
10
11
  require_relative "../lib/kdwatch/version"
11
12
 
12
13
  KDWATCH_PORT = 7991 # currently unregistered...
13
14
 
15
+ def socket_is_free(host, port, uri)
16
+ begin
17
+ TCPSocket.new(host, port, connect_timeout: 1)
18
+ rescue Errno::ECONNREFUSED => e
19
+ return true
20
+ rescue => e
21
+ warn "*** #{uri} -- #{e.inspect}"
22
+ return nil # break, but don't use
23
+ end
24
+ return false
25
+ end
26
+
14
27
  options = OpenStruct.new
15
28
 
16
29
  op = OptionParser.new do |opts|
@@ -30,7 +43,7 @@ BANNER
30
43
  opts.on("-r", "--[no-]replace", "Replace existing server")
31
44
  opts.on("-oNAME", "--host=NAME", String, "Server host (127.0.0.1)")
32
45
  opts.on("-i", "--internet", 'Abbr. "on the Internet" (host = "::")')
33
- opts.on("-pNUM", "--port=NUM", Integer, "Port number (#{KDWATCH_PORT})")
46
+ opts.on("-pNUM", "--port=NUM", Integer, "Port number (#{KDWATCH_PORT}...)")
34
47
  opts.on("-[1-6]", "--[1-6]", Integer, "Abbr. port number (#{KDWATCH_PORT/10}x), must be last")
35
48
  end
36
49
  begin
@@ -52,7 +65,26 @@ if short_port = options[""]
52
65
  warn "** overriding port #{options.port} with #{port}" if options.port
53
66
  options.port = port
54
67
  else
55
- options.port ||= KDWATCH_PORT
68
+ unless options.port
69
+ port = KDWATCH_PORT
70
+ host = options.host
71
+ host = "[#{host}]" if host =~ /:/
72
+ uri = nil
73
+ found = false
74
+ 100.times do
75
+ uri = "http://#{host}:#{port}"
76
+ # warn "Trying URI #{uri}"
77
+ found = socket_is_free(options.host, port, uri)
78
+ break unless found == false
79
+ port += 1
80
+ end
81
+ unless found
82
+ warn "*** Cannot find port number available to serve from!"
83
+ exit 1
84
+ end
85
+ warn "*** Using URI: #{uri}"
86
+ options.port = port
87
+ end
56
88
  end
57
89
 
58
90
  # p options
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdwatch
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-03 00:00:00.000000000 Z
11
+ date: 2022-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  requirements: []
160
- rubygems_version: 3.2.32
160
+ rubygems_version: 3.3.11
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: 'kdwatch: open auto-reloaded HTML for kramdown-rfc in a browser.'