diff options
author | kballou <kballou@devnulllabs.io> | 2016-10-30 22:54:39 -0600 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2016-10-30 23:07:59 -0600 |
commit | 35325ce024b36672aca33f08bf61adf3570445bf (patch) | |
tree | 01cfc3f240faf82ca0f72b137fc57365f0df51e3 /lib/octochat/acceptor.ex | |
parent | 10275f7bbf7c79214a52e837294a8c16fdfaa549 (diff) | |
download | octochat-35325ce024b36672aca33f08bf61adf3570445bf.tar.gz octochat-35325ce024b36672aca33f08bf61adf3570445bf.tar.xz |
Add connection acceptorv0.1.0
This adds a basic connection acceptor that immediately closes accepted
connections and beings to flesh out the supervision tree.
Diffstat (limited to 'lib/octochat/acceptor.ex')
-rw-r--r-- | lib/octochat/acceptor.ex | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/octochat/acceptor.ex b/lib/octochat/acceptor.ex new file mode 100644 index 0000000..66d97fc --- /dev/null +++ b/lib/octochat/acceptor.ex @@ -0,0 +1,21 @@ +defmodule Octochat.Acceptor do + @moduledoc """ + Connection/socket accpetor + """ + + @listen_port Application.get_env(:octochat, :port) || 9999 + + def accept do + {:ok, socket} = :gen_tcp.listen( + @listen_port, + [:binary, packet: :line, active: false, reuseaddr: true]) + loop_acceptor(socket) + end + + defp loop_acceptor(socket) do + {:ok, client} = :gen_tcp.accept(socket) + :gen_tcp.close(client) + loop_acceptor(socket) + end + +end |