init
This commit is contained in:
commit
2bdec198d8
4
.formatter.exs
Normal file
4
.formatter.exs
Normal file
@ -0,0 +1,4 @@
|
||||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# The directory Mix will write compiled artifacts to.
|
||||
/_build/
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover/
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps/
|
||||
|
||||
# Where third-party dependencies like ExDoc output generated docs.
|
||||
/doc/
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
warden-*.tar
|
||||
|
||||
# Temporary files, for example, from tests.
|
||||
/tmp/
|
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Warden
|
||||
|
||||
**TODO: Add description**
|
||||
|
||||
## Installation
|
||||
|
||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
||||
by adding `warden` to your list of dependencies in `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:warden, "~> 0.1.0"}
|
||||
]
|
||||
end
|
||||
```
|
||||
|
||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
||||
be found at <https://hexdocs.pm/warden>.
|
||||
|
34
lib/server/connection/conn.ex
Normal file
34
lib/server/connection/conn.ex
Normal file
@ -0,0 +1,34 @@
|
||||
defmodule Server.Conn do
|
||||
require Logger
|
||||
use GenServer
|
||||
|
||||
@impl true
|
||||
def init(_args) do
|
||||
initial_state = %{"num_conns" => 0}
|
||||
{:ok, initial_state}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_call(_socket, _from, _state) do
|
||||
throw("call is unimplementedd")
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_cast(socket, state) do
|
||||
spawn(handle(socket))
|
||||
|
||||
%{"num_conns" => state.num_conns + 1}
|
||||
end
|
||||
|
||||
defp handle(socket) do
|
||||
case :gen_tcp.recv(socket, 1024) do
|
||||
{:ok, packet} ->
|
||||
Logger.debug("[Server.Conn] packet #{packet}")
|
||||
{:error, reason} ->
|
||||
Logger.error("[Server.Conn] failed to read connection: #{reason}")
|
||||
|
||||
end
|
||||
|
||||
handle(socket)
|
||||
end
|
||||
end
|
17
lib/server/server.ex
Normal file
17
lib/server/server.ex
Normal file
@ -0,0 +1,17 @@
|
||||
defmodule Server do
|
||||
def start(addr) do
|
||||
accept_loop(addr)
|
||||
end
|
||||
|
||||
defp accept_loop(addr) do
|
||||
case :gen_tcp.accept(addr) do
|
||||
{:ok, socket} ->
|
||||
accept(socket)
|
||||
end
|
||||
accept_loop(addr)
|
||||
end
|
||||
|
||||
defp accept(socket) do
|
||||
send(Server.Conn, socket)
|
||||
end
|
||||
end
|
10
lib/warden.ex
Normal file
10
lib/warden.ex
Normal file
@ -0,0 +1,10 @@
|
||||
defmodule Warden do
|
||||
use Application
|
||||
|
||||
def start(_type, _args) do
|
||||
children = [
|
||||
Server,
|
||||
]
|
||||
Supervisor.start_link(children, strategy: :one_for_one)
|
||||
end
|
||||
end
|
29
mix.exs
Normal file
29
mix.exs
Normal file
@ -0,0 +1,29 @@
|
||||
defmodule Warden.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :warden,
|
||||
version: "0.1.0",
|
||||
elixir: "~> 1.18",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
mod: {Warden, []},
|
||||
extra_applications: [:logger]
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
# {:dep_from_hexpm, "~> 0.3.0"},
|
||||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
|
||||
]
|
||||
end
|
||||
end
|
1
test/test_helper.exs
Normal file
1
test/test_helper.exs
Normal file
@ -0,0 +1 @@
|
||||
ExUnit.start()
|
8
test/warden_test.exs
Normal file
8
test/warden_test.exs
Normal file
@ -0,0 +1,8 @@
|
||||
defmodule WardenTest do
|
||||
use ExUnit.Case
|
||||
doctest Warden
|
||||
|
||||
test "greets the world" do
|
||||
assert Warden.hello() == :world
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user