Squashed 'third_party/rawrtc/re/' content from commit f3163ce8b
Change-Id: I6a235e6ac0f03269d951026f9d195da05c40fdab
git-subtree-dir: third_party/rawrtc/re
git-subtree-split: f3163ce8b526a13b35ef71ce4dd6f43585064d8a
diff --git a/include/re_tcp.h b/include/re_tcp.h
new file mode 100644
index 0000000..98dba71
--- /dev/null
+++ b/include/re_tcp.h
@@ -0,0 +1,101 @@
+/**
+ * @file re_tcp.h Interface to Transport Control Protocol
+ *
+ * Copyright (C) 2010 Creytiv.com
+ */
+struct sa;
+struct tcp_sock;
+struct tcp_conn;
+
+
+/**
+ * Defines the incoming TCP connection handler
+ *
+ * @param peer Network address of peer
+ * @param arg Handler argument
+ */
+typedef void (tcp_conn_h)(const struct sa *peer, void *arg);
+
+/**
+ * Defines the TCP connection established handler
+ *
+ * @param arg Handler argument
+ */
+typedef void (tcp_estab_h)(void *arg);
+
+/**
+ * Defines the TCP connection data send handler
+ *
+ * @param arg Handler argument
+ */
+typedef void (tcp_send_h)(void *arg);
+
+/**
+ * Defines the TCP connection data receive handler
+ *
+ * @param mb Buffer with data
+ * @param arg Handler argument
+ */
+typedef void (tcp_recv_h)(struct mbuf *mb, void *arg);
+
+/**
+ * Defines the TCP connection close handler
+ *
+ * @param err Error code
+ * @param arg Handler argument
+ */
+typedef void (tcp_close_h)(int err, void *arg);
+
+
+/* TCP Socket */
+int tcp_sock_alloc(struct tcp_sock **tsp, const struct sa *local,
+ tcp_conn_h *ch, void *arg);
+int tcp_sock_bind(struct tcp_sock *ts, const struct sa *local);
+int tcp_sock_listen(struct tcp_sock *ts, int backlog);
+int tcp_accept(struct tcp_conn **tcp, struct tcp_sock *ts, tcp_estab_h *eh,
+ tcp_recv_h *rh, tcp_close_h *ch, void *arg);
+void tcp_reject(struct tcp_sock *ts);
+int tcp_sock_local_get(const struct tcp_sock *ts, struct sa *local);
+
+
+/* TCP Connection */
+int tcp_conn_alloc(struct tcp_conn **tcp, const struct sa *peer,
+ tcp_estab_h *eh, tcp_recv_h *rh, tcp_close_h *ch,
+ void *arg);
+int tcp_conn_bind(struct tcp_conn *tc, const struct sa *local);
+int tcp_conn_connect(struct tcp_conn *tc, const struct sa *peer);
+int tcp_send(struct tcp_conn *tc, struct mbuf *mb);
+int tcp_set_send(struct tcp_conn *tc, tcp_send_h *sendh);
+void tcp_set_handlers(struct tcp_conn *tc, tcp_estab_h *eh, tcp_recv_h *rh,
+ tcp_close_h *ch, void *arg);
+void tcp_conn_rxsz_set(struct tcp_conn *tc, size_t rxsz);
+void tcp_conn_txqsz_set(struct tcp_conn *tc, size_t txqsz);
+int tcp_conn_local_get(const struct tcp_conn *tc, struct sa *local);
+int tcp_conn_peer_get(const struct tcp_conn *tc, struct sa *peer);
+int tcp_conn_fd(const struct tcp_conn *tc);
+size_t tcp_conn_txqsz(const struct tcp_conn *tc);
+
+
+/* High-level API */
+int tcp_listen(struct tcp_sock **tsp, const struct sa *local,
+ tcp_conn_h *ch, void *arg);
+int tcp_connect(struct tcp_conn **tcp, const struct sa *peer,
+ tcp_estab_h *eh, tcp_recv_h *rh, tcp_close_h *ch, void *arg);
+int tcp_local_get(const struct tcp_sock *ts, struct sa *local);
+
+
+/* Helper API */
+typedef bool (tcp_helper_estab_h)(int *err, bool active, void *arg);
+typedef bool (tcp_helper_send_h)(int *err, struct mbuf *mb, void *arg);
+typedef bool (tcp_helper_recv_h)(int *err, struct mbuf *mb, bool *estab,
+ void *arg);
+
+struct tcp_helper;
+
+
+int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc,
+ int layer,
+ tcp_helper_estab_h *eh, tcp_helper_send_h *sh,
+ tcp_helper_recv_h *rh, void *arg);
+int tcp_send_helper(struct tcp_conn *tc, struct mbuf *mb,
+ struct tcp_helper *th);