Raw TCP/IP interface for lwIP
Authors: Adam Dunkels, Leon Woestenberg, Christiaan Simons
lwIP provides three Application Program's Interfaces (APIs) for programs
to use for communication with the TCP/IP code:
* low-level "core" / "callback" or "raw" API.
* higher-level "sequential" API.
* BSD-style socket API.
The sequential API provides a way for ordinary, sequential, programs
to use the lwIP stack. It is quite similar to the BSD socket API. The
model of execution is based on the blocking open-read-write-close
paradigm. Since the TCP/IP stack is event based by nature, the TCP/IP
code and the application program must reside in different execution
contexts (threads).
The socket API is a compatibility API for existing applications,
currently it is built on top of the sequential API. It is meant to
provide all functions needed to run socket API applications running
on other platforms (e.g. unix / windows etc.). However, due to limitations
in the specification of this API, there might be incompatibilities
that require small modifications of existing programs.
** Threading
lwIP started targeting single-threaded environments. When adding multi-
threading support, instead of making the core thread-safe, another
approach was chosen: there is one main thread running the lwIP core
(also known as the "tcpip_thread"). The raw API may only be used from
this thread! Application threads using the sequential- or socket API
communicate with this main thread through message passing.
As such, the list of functions that may be called from
other threads or an ISR is very limited! Only functions
from these API header files are thread-safe:
- api.h
- netbuf.h
- netdb.h
- netifapi.h
- sockets.h
- sys.h
Additionaly, memory (de-)allocation functions may be
called from multiple threads (not ISR!) with NO_SYS=0
since they are protected by SYS_LIGHTWEIGHT_PROT and/or
semaphores.
Only since 1.3.0, if SYS_LIGHTWEIGHT_PROT is set to 1
and LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is set to 1,
pbuf_free() may also be called from another thread or
an ISR (since only then, mem_free - for PBUF_RAM - may
be called from an ISR: otherwise, the HEAP is only
protected by semaphores).
** The remainder of this document discusses the "raw" API. **
The raw TCP/IP interface allows the application program to integrate
better with the TCP/IP code. Program execution is event based by
having callback functions being called from within the TCP/IP
code. The TCP/IP code and the application program both run in the same
thread. The sequential API has a much higher overhead and is not very
well suited for small systems since it forces a multithreaded paradigm
on the application.
The raw TCP/IP interface is not only faster in terms of code execution
time but is also less memory intensive. The drawback is that program
development is somewhat harder and application programs written for
the raw TCP/IP interface are more difficult to understand. Still, this
is the preferred way of writing applications that should be small in
code size and memory usage.
Both APIs can be used simultaneously by different application
programs. In fact, the sequential API is implemented as an application
program using the raw TCP/IP interface.
--- Callbacks
Program execution is driven by callbacks. Each callback is an ordinary
C function that is called from within the TCP/IP code. Every callback
function is passed the current TCP or UDP connection state as an
argument. Also, in order to be able to keep program specific state,
the callback functions are called with a program specified argument
that is independent of the TCP/IP state.
The function for setting the application connection state is:
- void tcp_arg(struct tcp_pcb *pcb, void *arg)
Specifies the program specific state that should be passed to all
other callback functions. The "pcb" argument is the current TCP
connection control block, and the "arg" argument is the argument
that will be passed to the callbacks.
--- TCP connection setup
The functions used for setting up connections is similar to that of
the sequential API and of the BSD socket API. A new TCP connection
identifier (i.e., a protocol control block - PCB) is created with the
tcp_new() function. This PCB can then be either set to listen for new
incoming connections or be explicitly connected to another host.
- struct tcp_pcb *tcp_new(void)
Creates a new connection identifier (PCB). If memory is not
available for creating the new pcb, NULL is returned.
- err_t tcp_bind(struct tcp_pcb *pcb, ip_addr_t *ipaddr,
u16_t port)
Binds the pcb to a local IP address and port number. The IP address
can be specified as IP_ADDR_ANY in order to bind the connection to
all local IP addresses.
If another connection is bound to the same port, the function will
return ERR_USE, otherwise ERR_OK is returned.
- struct tcp_pcb *tcp_listen(struct tcp_pcb *pcb)
Commands a pcb to start listening for incoming connections. When an
incoming connection is accepted, the function specified with the
tcp_accept() function will be called. The pcb will have to be bound
to a local port with the tcp_bind() function.
The tcp_listen() function returns a new connection identifier, and
the one passed as an argument to the function will be
deallocated. The reason for this behavior is that less memory is
needed for a connection that is listening, so tcp_listen() will
reclaim the memory needed for the original connection and allocate a
new smaller memory block for the listening connection.
tcp_listen() may return NULL if no memory was available for the
listening connection. If so, the memory associated with the pcb
passed as an argument to tcp_listen() will not be deallocated.
- struct tcp_pcb *tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
Same as tcp_listen, but limits the number of outstanding connections
in the listen queue to the value specified by the backlog argument.
To use it, your need to set TCP_LISTEN_BACKLOG=1 in your lwipopts.h.
- void tcp_accepted(struct tcp_pcb *pcb)
Inform lwIP that an incoming connection has been accepted. This would
usually be called from the accept callback. This allows lwIP to perform
housekeeping tasks, such as allowing further incoming connections to be
queued in the listen backlog.
ATTENTION: the PCB passed in must be the listening pcb, not the pcb passed
into the accept callback!
- void tcp_accept(struct tcp_pcb *pcb,
err_t (* accept)(void *arg, struct tcp_pcb *newpcb,
err_t err))
Specified the callback function that should be called when a new
connection arrives on a listening connection.
- err_t tcp_connect(struct tcp_pcb *pcb, ip_addr_t *ipaddr,
u16_t port, err_t (* connected)(void *arg,
struct tcp_pcb *tpcb,
err_t err));
Sets up the pcb to connect to the remote host and sends the
initial SYN segment which opens the connection.
The tcp_connect() function returns immediately; it does not wait for
the connection to be properly setup. Instead, it will call the
function specified as the fourth argument (the "connected" argument)
when the connection is established. If the connection could not be
properly established, either because the other host refused the
connection or because the other host didn't answer, the "err"
callback function of this pcb (registered with tcp_err, see below)
will be called.
The tcp_connect() function can return ERR_MEM if no memory is
available for enqueueing the SYN
没有合适的资源?快使用搜索试试~ 我知道了~
stm32 code 整理
共2120个文件
c:537个
h:299个
s:59个
需积分: 0 0 下载量 14 浏览量
2023-07-25
22:46:41
上传
评论
收藏 34.24MB RAR 举报
温馨提示
stm32 code 整理
资源推荐
资源详情
资源评论
收起资源包目录
stm32 code 整理 (2120个子文件)
00119ee7f9b0cd2ff23b37d679f04bab0f65b6 9KB
0039cdd9fd34a19e627d3f484493b5a77ca971 47KB
007e80f22efdbe69e4b8354f80e47bf55e50ba 93B
01107a7e8f71283056a2a94c349648f0ec3e90 3KB
011fea710077c61469ff06e0d8563103a382aa 2KB
012696db05e62f01dbd6befb4c68adc5abcd02 3KB
0148eaa1f52d4d22fadc4121cd995108185c7e 1KB
018651f9cb80e3751c7ca5565ce5af25544c89 1KB
01ab1bdcf1b8b6d408fd794021485f392e7a54 1KB
01cb10de74e763f6657bf8bd5a498a7b18e746 10KB
023d7f7d831fd33c5fcde687a70004db37f6c7 937B
0252f64f1a6d8ccf033f41d819f8d1d214344d 4KB
027816722ef2ce90cd4ee22d91a2960e4b8e08 7KB
02d70754cdddb0a3cb833f60565892e5cab820 2KB
02dfccb3afc5bb80b45b4a15592e33748d174a 2KB
02e77f31f24ec0cf470631f79879ad171cf5ce 7KB
0339eaccb33c5503edf3a11d7a8310bcd03416 73B
033a8b9995b7cbba2665fbf0d4de61ec7df57d 272B
036f0a42cb816d28f8010e190167750d6424df 45B
03da352630edd39f40b753716a516b1e49a854 710B
03f460ecb435d51f6cb1f0e0225cb5a5df106b 2KB
03f75193035c49636dc03550fca32b0882c9c1 6KB
0475630a02a11164f4579fbe1a481e94a52c6f 3KB
047bf14c72e6ae638e83ddb9736596b342c82a 252B
04ea840a205296c56187b9eccad2126c774504 2KB
04ed1b6a9a20645cef70baa9fd70b585943557 2KB
054c69372eb594690d22514dcd1ea469351a5d 1KB
054d34b73c179c141dfbc5cb6b6a5020fe130e 2KB
0560b4b84b8db5a0bf7ef3920f753620d97cf6 45B
056f4dfc2c9d612d2bc9579ea414c8f3a76291 4KB
05713bf05240fd487de0438841b9c24abd2b8b 2KB
0579731c108f6df8ba55abf7c25d46a2c20da7 898B
065e92907eab7cc2b6c5dd8ec491fb14de8557 2KB
068b2e9924463cfaf9acd6bacd2aff00dde058 2KB
06921299b94ca02dd0019577ee56c77529c26a 4KB
069ec4640f9c4fe6caa2554a8f9666a16bd92d 2KB
069fa125dac3f3c0fffcbc2e716b53674f581b 444B
06c0bc83bdb9bece06626a8ece84b3fd446bdf 467B
06fac174e98f3711ba60496e53aaa61c470c6d 55B
07030ed0e49b4ee613d84c1a1380ffe5ba95a0 866B
070fb356bd2fe6c67463d5c1dc954872a8c8bb 1KB
0715c5acc04eeae87afff056af0cb39e66ed3f 4.51MB
073c43533d8b9150d74e405e87ad01edbb183f 4KB
0846660aff0d7f7a7d564535544497eff93286 4KB
08604501a669363269b8ab47d27c4c9dfff385 8KB
086818002f9427cc3b123bdac0000cf0fd5583 135B
087ac9938154ea9b8898019e18f39fb8033bb9 4KB
0898a3429718d645deb1766b62968eac0d16ce 2KB
08bed1524570a72b8255844ecb966adaf0907c 5KB
08cb84c25b35fe3b28a1a3791e0252d516342a 2KB
08cd6645c499096aa8303fabf8e690ae18dc23 139B
091acd35f177a5095908e8b970c2bda428beb3 5KB
092e0263d83143f2add8be6266c2200f69b68c 2KB
09d91af226d3d5bf3f5fbbee146f6547e3634f 11KB
0a54a5f621c329a4f197f8073c6b6c6bce38f5 1KB
0a58f1c320257abfb49b685d9c0b10df39f450 339B
0aa4c80498c414d03990212ceab4103df9ff8d 2KB
0aaa1a10fd52df5d031fc74d6691bfb76f611b 238B
0abe6fc4d7d56f78c2712a4e6dc768f369884e 46B
0ac9555b864d6921fdda7165fc006b97b5492c 645B
0b3509ef2e763b401ce1bc0f68e4f4e566ae81 1KB
0b47e23ad9a315b4140d97b2eba0ec47805559 237B
0bba4d90803220093b3121467a3c6a837d91b3 535B
0bc71382582721d032e43988fb15e77988a43a 848B
0bfd75b805766a2ea3fea7474780b1d22cb6d8 428B
0c38969e879e46cf50b7e6ed9a87d871a03f63 5KB
0c739c4eb95ec2bbbba0e862042f283d0afad6 2KB
0c9fc88e52780011502405ee8ebf468af25ed8 4KB
0cd3f0ff5913d2b337a77bd1bb66be938c02bc 4KB
0db7f708fd92e2b5fefb6b2f67f56842723c48 2KB
0ddbe286a876d4eaed35c9a0be27a39fc51f80 7KB
0e151c8c116952850861721675dc93a32d20cc 2KB
0e27d2eaf0b89de5429b10765a71efbc71c384 8KB
0e28c9894ebf1d0da6534ddff5ebbbede7a7f5 177B
0e30cd74facf0d1385458a5b430b95a982b0fe 51B
0e5e86765d3e871156e9cbfe49a2c4fc57bba5 1KB
0ea7d709df2e51a65030d6eb4fabf83ff74908 2KB
0ecc9c76ff206b83a61387d1cd2adb09fbcba3 72B
0ed05c2c052533679f45dd9de176fb3f5fb754 5KB
0ee679ced9cb37096dbe49a95b824de305fe2b 1KB
0f37af6d798faf15fbd3a172564df6969e1f5c 2KB
0fd5dca77607058516b61358db96ffbf7bb936 128B
102b4cbf1df65a1604848eb51b95856827661d 1KB
10356249878f00c1748ed307b8438cab527854 6KB
106eac0fa8bc7e7cdc73bf94365eafcaf776b0 10KB
10a316374be3192c71b44bfd894d01a05033f6 36B
10b783179241e12f06f320b23bbbae865f0095 500B
10d2e2a4699bb2135f31e953a9dd31433eaf18 17KB
10efad0a3f923fdec4d256bfb6260fb38f952e 413B
10f292a0ffc439a2838619b69d39603855888a 5KB
10ff5e137a3000c9b107d3c236d092e5a401ad 4KB
111660b82136359440344d0fd46a2c5f459d62 4KB
114857dfef2ef8728d5a17560fadbace484f18 151B
1197366ac0a4a41235bea49dcda462e37b8907 6KB
11a133d17d4b98fb89da5453ad47b9b89ad97b 5KB
11a1e8b3c0cb1d3de2ae7e50e4d84e770d9e96 5KB
11b0f9be04e345a06a94678ea682487b41531e 2KB
1223ed1fc509484750ea06fc142ce60a0c48d7 341B
12791280e1111c4374d1102ad5ff46f5abe987 613B
12c550219622c34bdfbd48bacb7bcdf63f2959 17KB
共 2120 条
- 1
- 2
- 3
- 4
- 5
- 6
- 22
资源评论
lcz997170576
- 粉丝: 1
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Qt开发知识、经验总结 包括Qss,数据库,Excel,Model/View等
- IV数据.xlsx
- 一些深度学习中的小例子,适合新手学习使用
- foldcraftlauncher_262944.apk
- 珍藏多年的基于matlab实现潮流计算程序源代码集合,包含多个潮流计算程序.rar
- 使用FPGA实现串-并型乘法器
- 基于matlab实现针对基于双曲线定位的DV-Hop算法中误差误差出一种基于加权双曲线定位的DV-Hop改进算法.rar
- 基于matlab实现由遗传算法开发的整数规划,车辆调度问题.rar
- 电视家7.0(对电视配置要求高).apk
- 免费计算机毕业设计-基于JavaEE的医院病历管理系统设计与实现(包含论文+源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功