Skip to content

Commit

Permalink
Merge pull request #13 from lpil/fix
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
rawhat authored Jan 15, 2024
2 parents 453f71e + 0d5fe50 commit 64e68c9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.10.0

- Updated for Gleam v0.33.0.
- The `options.to_map` function has been renamed to `options.to_dict`.

# v0.9.1

- Pass state value to `on_close` handler
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "glisten"
version = "0.9.2"
version = "0.10.0"
description = "a shiny Gleam TCP/SSL server"
licences = ["Apache-2.0"]
repository = { type = "github", user = "rawhat", repo = "glisten" }
Expand Down
14 changes: 7 additions & 7 deletions src/glisten/socket/options.gleam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gleam/dynamic.{type Dynamic}
import gleam/erlang/atom
import gleam/list
import gleam/map.{type Map}
import gleam/dict.{type Dict}
import gleam/pair

/// Mode for the socket. Currently `list` is not supported
Expand Down Expand Up @@ -36,7 +36,7 @@ pub type TcpOption {
Inet6
}

pub fn to_map(options: List(TcpOption)) -> Map(atom.Atom, Dynamic) {
pub fn to_dict(options: List(TcpOption)) -> Dict(atom.Atom, Dynamic) {
let opt_decoder = dynamic.tuple2(dynamic.dynamic, dynamic.dynamic)

options
Expand All @@ -58,7 +58,7 @@ pub fn to_map(options: List(TcpOption)) -> Map(atom.Atom, Dynamic) {
})
|> list.filter_map(opt_decoder)
|> list.map(pair.map_first(_, dynamic.unsafe_coerce))
|> map.from_list
|> dict.from_list
}

const default_options = [
Expand All @@ -73,12 +73,12 @@ const default_options = [
]

pub fn merge_with_defaults(options: List(TcpOption)) -> List(TcpOption) {
let overrides = to_map(options)
let overrides = to_dict(options)

default_options
|> to_map
|> map.merge(overrides)
|> map.to_list
|> to_dict
|> dict.merge(overrides)
|> dict.to_list
|> list.map(dynamic.from)
|> list.map(dynamic.unsafe_coerce)
|> list.append([Inet6])
Expand Down
6 changes: 3 additions & 3 deletions src/glisten/socket/transport.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gleam/bit_builder.{type BitBuilder}
import gleam/dynamic.{type Dynamic}
import gleam/erlang/atom.{type Atom}
import gleam/erlang/process.{type Pid}
import gleam/map.{type Map}
import gleam/dict.{type Dict}
import glisten/socket/options
import glisten/socket.{type ListenSocket, type Socket, type SocketReason}
import glisten/ssl
Expand Down Expand Up @@ -30,7 +30,7 @@ type Send =
fn(Socket, BitBuilder) -> Result(Nil, SocketReason)

type SocketInfo =
fn(Socket) -> Map(Atom, Dynamic)
fn(Socket) -> Dict(Atom, Dynamic)

type Close =
fn(Socket) -> Result(Nil, SocketReason)
Expand Down Expand Up @@ -126,4 +126,4 @@ pub fn ssl() -> Transport {
}

@external(erlang, "socket", "info")
pub fn socket_info(socket: Socket) -> Map(a, b)
pub fn socket_info(socket: Socket) -> Dict(a, b)
6 changes: 3 additions & 3 deletions src/glisten/ssl.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gleam/dynamic.{type Dynamic}
import gleam/erlang/atom.{type Atom}
import gleam/erlang/process.{type Pid}
import gleam/list
import gleam/map
import gleam/dict
import glisten/socket.{type ListenSocket, type Socket, type SocketReason}
import glisten/socket/options

Expand Down Expand Up @@ -58,8 +58,8 @@ pub fn set_opts(
opts: List(options.TcpOption),
) -> Result(Nil, Nil) {
opts
|> options.to_map
|> map.to_list
|> options.to_dict
|> dict.to_list
|> list.map(dynamic.from)
|> do_set_opts(socket, _)
}
Expand Down
8 changes: 4 additions & 4 deletions src/glisten/tcp.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gleam/dynamic.{type Dynamic}
import gleam/erlang/atom.{type Atom}
import gleam/erlang/process.{type Pid}
import gleam/list
import gleam/map.{type Map}
import gleam/dict.{type Dict}
import glisten/socket.{type ListenSocket, type Socket, type SocketReason}
import glisten/socket/options.{type TcpOption}

Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn receive(socket: Socket, length: Int) -> Result(BitArray, SocketReason)
pub fn send(socket: Socket, packet: BitBuilder) -> Result(Nil, SocketReason)

@external(erlang, "socket", "info")
pub fn socket_info(socket: Socket) -> Map(a, b)
pub fn socket_info(socket: Socket) -> Dict(a, b)

@external(erlang, "glisten_tcp_ffi", "close")
pub fn close(socket: a) -> Result(Nil, SocketReason)
Expand All @@ -58,8 +58,8 @@ fn do_set_opts(socket: Socket, opts: List(Dynamic)) -> Result(Nil, Nil)
/// Update the optons for a socket (mutates the socket)
pub fn set_opts(socket: Socket, opts: List(TcpOption)) -> Result(Nil, Nil) {
opts
|> options.to_map
|> map.to_list
|> options.to_dict
|> dict.to_list
|> list.map(dynamic.from)
|> do_set_opts(socket, _)
}
Expand Down

0 comments on commit 64e68c9

Please sign in to comment.