/**
* @file
* Sockets BSD-Like API module
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* Improved by Marc Boucher <marc@mbsi.ca> and David Haas <dhaas@alum.rpi.edu>
*
*/
#include "lwip/opt.h"
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
#include "lwip/sockets.h"
#include "lwip/api.h"
#include "lwip/sys.h"
#include "lwip/igmp.h"
#include "lwip/inet.h"
#include "lwip/tcp.h"
#include "lwip/raw.h"
#include "lwip/udp.h"
#include "lwip/tcpip.h"
#include "lwip/pbuf.h"
#if LWIP_CHECKSUM_ON_COPY
#include "lwip/inet_chksum.h"
#endif
#include <string.h>
#define NUM_SOCKETS MEMP_NUM_NETCONN
/** Contains all internal pointers and states used for a socket */
struct lwip_sock {
/** sockets currently are built on netconns, each socket has one netconn */
struct netconn *conn;
/** data that was left from the previous read */
void *lastdata;
/** offset in the data that was left from the previous read */
u16_t lastoffset;
/** number of times data was received, set by event_callback(),
tested by the receive and select functions */
s16_t rcvevent;
/** number of times data was ACKed (free send buffer), set by event_callback(),
tested by select */
u16_t sendevent;
/** error happened for this socket, set by event_callback(), tested by select */
u16_t errevent;
/** last error that occurred on this socket */
int err;
/** counter of how many threads are waiting for this socket using select */
int select_waiting;
};
/** Description for a task waiting in select */
struct lwip_select_cb {
/** Pointer to the next waiting task */
struct lwip_select_cb *next;
/** Pointer to the previous waiting task */
struct lwip_select_cb *prev;
/** readset passed to select */
fd_set *readset;
/** writeset passed to select */
fd_set *writeset;
/** unimplemented: exceptset passed to select */
fd_set *exceptset;
/** don't signal the same semaphore twice: set to 1 when signalled */
int sem_signalled;
/** semaphore to wake up a task waiting for select */
sys_sem_t sem;
};
/** This struct is used to pass data to the set/getsockopt_internal
* functions running in tcpip_thread context (only a void* is allowed) */
struct lwip_setgetsockopt_data {
/** socket struct for which to change options */
struct lwip_sock *sock;
#ifdef LWIP_DEBUG
/** socket index for which to change options */
int s;
#endif /* LWIP_DEBUG */
/** level of the option to process */
int level;
/** name of the option to process */
int optname;
/** set: value to set the option to
* get: value of the option is stored here */
void *optval;
/** size of *optval */
socklen_t *optlen;
/** if an error occures, it is temporarily stored here */
err_t err;
};
/** The global array of available sockets */
static struct lwip_sock sockets[NUM_SOCKETS];
/** The global list of tasks waiting for select */
static struct lwip_select_cb *select_cb_list;
/** This counter is increased from lwip_select when the list is chagned
and checked in event_callback to see if it has changed. */
static volatile int select_cb_ctr;
/** Table to quickly map an lwIP error (err_t) to a socket error
* by using -err as an index */
static const int err_to_errno_table[] = {
0, /* ERR_OK 0 No error, everything OK. */
ENOMEM, /* ERR_MEM -1 Out of memory error. */
ENOBUFS, /* ERR_BUF -2 Buffer error. */
EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
EINVAL, /* ERR_VAL -6 Illegal value. */
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
ECONNABORTED, /* ERR_ABRT -8 Connection aborted. */
ECONNRESET, /* ERR_RST -9 Connection reset. */
ESHUTDOWN, /* ERR_CLSD -10 Connection closed. */
ENOTCONN, /* ERR_CONN -11 Not connected. */
EIO, /* ERR_ARG -12 Illegal argument. */
EADDRINUSE, /* ERR_USE -13 Address in use. */
-1, /* ERR_IF -14 Low-level netif error */
-1, /* ERR_ISCONN -15 Already connected. */
};
#define ERR_TO_ERRNO_TABLE_SIZE \
(sizeof(err_to_errno_table)/sizeof(err_to_errno_table[0]))
#define err_to_errno(err) \
((unsigned)(-(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \
err_to_errno_table[-(err)] : EIO)
#ifdef ERRNO
#ifndef set_errno
#define set_errno(err) errno = (err)
#endif
#else /* ERRNO */
#define set_errno(err)
#endif /* ERRNO */
#define sock_set_errno(sk, e) do { \
sk->err = (e); \
set_errno(sk->err); \
} while (0)
/* Forward delcaration of some functions */
static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len);
static void lwip_getsockopt_internal(void *arg);
static void lwip_setsockopt_internal(void *arg);
/**
* Initialize this module. This function has to be called before any other
* functions in this module!
*/
void
lwip_socket_init(void)
{
}
/**
* Map a externally used socket index to the internal socket representation.
*
* @param s externally used socket index
* @return struct lwip_sock for the socket or NULL if not found
*/
static struct lwip_sock *
get_socket(int s)
{
struct lwip_sock *sock;
if ((s < 0) || (s >= NUM_SOCKETS)) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s));
set_errno(EBADF);
return NULL;
}
sock = &sockets[s];
if (!sock->conn) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s));
set_errno(EBADF);
return NULL;
}
return sock;
}
/**
* Same as get_socket but doesn't set errno
*
* @param s externally used socket index
* @return struct lwip_sock for the socket or NULL if not found
*/
static struct lwip_sock *
tryget_socket(int s)
{
if ((s < 0) || (s >= NUM_SOCKETS)) {
return NULL;
}
if (!sockets[s].conn) {
return NULL;
}
return &sockets[s];
}
/**
* Allocate a new socket for a given netconn.
*
* @param newconn the netconn for which to allocate a socket
* @param accepted 1 if socket has been created by accept(),
* 0 if socket has been created by socket()
* @return the index of the new socket; -1 on error
*/
static int
alloc_
没有合适的资源?快使用搜索试试~ 我知道了~
基于ESP8266设计的安防控制器系统.zip(毕设/课设/竞赛/实训/项目开发)
共747个文件
h:271个
c:164个
makefile:60个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 166 浏览量
2024-03-29
20:22:59
上传
评论
收藏 34.44MB ZIP 举报
温馨提示
嵌入式优质项目,资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目。 本人单片机开发经验充足,深耕嵌入式领域,有任何使用问题欢迎随时与我联系,我会及时为你解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明,项目具体内容可查看下方的资源详情。 【附带帮助】: 若还需要嵌入式物联网单片机相关领域开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步。 【本人专注嵌入式领域】: 有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为你提供帮助,CSDN博客端可私信,为你解惑,欢迎交流。 【建议小白】: 在所有嵌入式开发中硬件部分若不会画PCB/电路,可选择根据引脚定义将其代替为面包板+杜邦线+外设模块的方式,只需轻松简单连线,下载源码烧录进去便可轻松复刻出一样的项目 【适合场景】: 相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可以基于此项目进行扩展来开发出更多功能
资源推荐
资源详情
资源评论
收起资源包目录
基于ESP8266设计的安防控制器系统.zip(毕设/课设/竞赛/实训/项目开发) (747个子文件)
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
gen_misc.bat 3KB
user1.1024.new.2.bin 390KB
user2.1024.new.2.bin 390KB
user2.2048.new.5.bin 390KB
user1.2048.new.5.bin 390KB
user1.1024.new.2.bin 387KB
user2.1024.new.2.bin 387KB
user2.2048.new.5.bin 387KB
user1.2048.new.5.bin 387KB
user1.1024.new.2.bin 387KB
user2.1024.new.2.bin 387KB
user2.2048.new.5.bin 387KB
user1.2048.new.5.bin 387KB
eagle.irom0text.bin 345KB
eagle.irom0text.bin 344KB
eagle.irom0text.bin 344KB
user2.4096.new.6.bin 272KB
user2.bin 272KB
user1.bin 272KB
user1.4096.new.6.bin 272KB
user1.bin 271KB
user2.bin 271KB
user2.4096.new.6.bin 271KB
user1.4096.new.6.bin 271KB
eagle.irom0text.bin 234KB
eagle.irom0text.bin 234KB
eagle.flash.bin 38KB
eagle.flash.bin 38KB
eagle.flash.bin 38KB
eagle.flash.bin 37KB
eagle.flash.bin 37KB
blank.bin 4KB
blank.bin 4KB
blank.bin 4KB
boot_v1.5.bin 3KB
boot_v1.5.bin 3KB
boot_v1.5.bin 3KB
boot_v1.2.bin 2KB
boot_v1.2.bin 2KB
boot_v1.2.bin 2KB
esp_init_data_default.bin 128B
esp_init_data_default.bin 128B
esp_init_data_default.bin 128B
boot_v1.5.bin_rep 3KB
boot_v1.5.bin_rep 3KB
boot_v1.5.bin_rep 3KB
esp_init_data_default.bin_rep 128B
esp_init_data_default.bin_rep 128B
esp_init_data_default.bin_rep 128B
sockets.c 67KB
dhcp.c 66KB
tcp_in.c 64KB
gw.c 64KB
user_webserver.c 63KB
user_webserver.c 63KB
user_webserver.c 63KB
gw.c 63KB
gw.c 57KB
tcp.c 54KB
etharp.c 51KB
tcp_out.c 50KB
espconn_tcp.c 47KB
user_esp_platform.c 45KB
user_esp_platform.c 45KB
user_esp_platform.c 45KB
api_msg.c 44KB
espconn.c 43KB
pbuf.c 40KB
dhcpserver.c 36KB
udp.c 33KB
sntp.c 32KB
ip.c 32KB
dns.c 31KB
mdns.c 30KB
ip_frag.c 28KB
igmp.c 27KB
uart.c 27KB
uart.c 27KB
uart.c 27KB
mem.c 22KB
api_lib.c 22KB
共 747 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2303
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功