/* DEBUG flag may be set for my internal playing */
/*
#define DEBUG
*/
/*
* PCTCP - the true worker of Waterloo TCP
* - contains all opens, closes, major read/write routines and
* basic IP handler for incomming packets
* - NOTE: much of the TCP/UDP/IP layering is done at the data structure
* level, not in separate routines or tasks
*
*/
#include <copyright.h>
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <mem.h>
#include <dos.h>
#include <values.h>
#include "wattcp.h"
#include "elib.h"
static void udp_handler(in_Header *ip);
static udp_write(udp_Socket *s, byte *datap, int len, word offset);
static int udp_read(udp_Socket *s, byte *datap, int maxlen);
static void tcp_Retransmitter(void);
#define TCP_LOCAL 0x4000
#define TCP_SAWCR 0x2000 // S. Lawson
/* statics */
//static tcp_ProcessData(tcp_Socket *s, tcp_Header *tp, int len);
static void tcp_ProcessData(tcp_Socket *s, tcp_Header *tp, int len, // 94.11.19
tcp_PseudoHeader *ph, word *flags); // S. Lawson
static char far *mono = (char far *)0xb0000000L;
static char far *colour = (char far *)0xb8000000L;
static initialized = 0;
void (*system_yield)() = NULL; /* 2000.4.14 EE */
extern int multihomes;
extern word _pktipofs;
void (*_dbugxmit)( sock_type *s, in_Header *inp, void *phdr, unsigned line ) = NULL;
void (*_dbugrecv)( sock_type *s, in_Header *inp, void *phdr, unsigned line ) = NULL;
void (*wattcpd)(void) = NULL;
char *_hostname = "012345678901234567890123456789012345678901234567890";
word _mss = ETH_MSS; // maximum size of *IP DATAGRAM*
word sock_data_timeout = 120; /* after 2 minutes we give up EE 99.08.23 */
char *_wattcp = WATTCP_C;
static void tcp_handler(in_Header *ip);
static void udp_handler(in_Header *ip);
static void tcp_unthread(tcp_Socket *ds);
static void tcp_abort(tcp_Socket *s);
void tcp_sendsoon(tcp_Socket *s );
static void tcp_send(tcp_Socket *s, int line);
static void tcp_rst( in_Header *his_ip, tcp_Header *oldtcpp);
static udp_close(udp_Socket *ds);
// AGW
// unsigned long later than for seq and ack comparisons -- allow for roll over
#define laterthan(x,y) ((long)((x)-(y))>0)
/*
* sock_yield - enable user defined yield function
*/
int sock_yield( tcp_Socket *s, void (*fn)( void ) )
{
if ( s )
s->usr_yield = fn;
else
system_yield = fn;
return( 0 );
}
/*
* sock_mode - set binary or ascii - affects sock_gets, sock_dataready
* - set udp checksums
*/
word sock_mode( sock_type *s, word mode )
{
return( s->tcp.sock_mode = (s->tcp.sock_mode & 0xfffc) | mode);
}
/*
* ip user level timer stuff
* void ip_timer_init( void *s, int delayseconds )
* int ip_timer_expired( void *s )
* - 0 if not expired
*/
static unsigned long far *realclock = (unsigned long far *)0x000046cL;
#define MAXTICKS 0x1800b0L
void ip_timer_init( sock_type *s , int delayseconds )
{
if (delayseconds)
s->tcp.usertimer = set_timeout( delayseconds );
else
s->tcp.usertimer = 0;
}
int ip_timer_expired( sock_type *s )
{
if (! s->tcp.usertimer) /* cannot expire */
return( 0 );
return( chk_timeout( s->tcp.usertimer));
}
longword MsecClock( void )
{
return( (*realclock) * 55L);
}
static long make_timeout( word timeout )
{
if ( timeout ) return( set_timeout( timeout ));
return( 0 );
}
#ifdef NOTUSED /* 94.11.27 -- not used? */
/*
* check_timeout - test agains timeout clock - account for overflow
*/
static int check_timeout( unsigned long timeout )
{
if (timeout) return( chk_timeout( timeout ));
return( 0 );
}
#endif
/*
* Local IP address
*/
longword my_ip_addr = 0L; /* for external references */
longword sin_mask = 0xfffffe00L;
longword sin_gate = 0x0;
/*
* IP identification numbers
*/
static int ip_id = 0; /* packet number */
static int next_tcp_port = 1024; /* auto incremented */
static int next_udp_port = 1024;
//static
tcp_Socket *tcp_allsocs = NULL;
static udp_Socket *udp_allsocs = NULL;
/* Timer definitions */
#define RETRAN_STRAT_TIME 1 /* in ticks - how often do we check retransmitter tables*/
#define tcp_RETRANSMITTIME 3 /* interval at which retransmitter is called */
#define tcp_LONGTIMEOUT 31 /* timeout for opens */
#define tcp_TIMEOUT 13 /* timeout during a connection */
#define LASTACK_TIMEOUT 10 // timeout in the LASTACK state added AGW 5th Jan 2001
// S. Lawson - define a short TIME_WAIT timeout that can be set in the
// makefile. It should be from .5 to 4 minutes (2MSL) but it's
// not really practical for us. 2 secs will hopefully handle the
// case where ACK must be retransmitted, but can't protect future
// connections on the same port from old packets.
#if !defined(TW_TO)
#define TW_TO 2
#endif
word debug_on = 0;
/*
* look for bugs
*/
int tcp_checkfor( sock_type *t )
{
tcp_Socket *p;
for ( p = tcp_allsocs ; p ; p = p->next )
if ( p == (tcp_Socket *)t ) return( 1 );
return( 0 );
}
/*
* Shut down the card and all services
*/
void tcp_shutdown( void )
{
while (tcp_allsocs)
tcp_abort( tcp_allsocs );
_eth_release();
initialized = 0;
}
// S. Lawson - keep an exiting tcp_init()
void tcp_init( void )
{
int r;
r=tcp_init_noexit();
if (r) exit(r);
}
/*
* tcp_init - Initialize the tcp implementation
* - may be called more than once without hurting
*/
int tcp_init_noexit( void ) // S. Lawson
{
extern int _arp_last_gateway;
extern int _last_nameserver;
if (!initialized) {
/* initialize ethernet interface */
initialized = 1;
// S. Lawson _eth_init();
if (_eth_init()) return 1; // S. Lawson
/* reset the various tables */
_arp_last_gateway = 0; /* reset the gateway table */
_last_nameserver = 0; /* reset the nameserver table */
_last_cookie = 0; /* eat all remaining crumbs */
*_hostname = 0; /* reset the host's name */
_eth_free( 0 );
next_udp_port = next_tcp_port = 1024 + ((int)(*realclock >> 7 )& 0x1ff);
}
return 0; // S. Lawson
}
// S. Lawson - initialize the port number counters
void tcp_set_ports(word tcp_base, word udp_base) {
if (tcp_base) next_tcp_port=(int) tcp_base;
if (udp_base) next_udp_port=(int) udp_base;
}
// S. Lawson - return current port number counters
void tcp_get_ports(word *tcp_base, word *udp_base) {
if (tcp_base) *tcp_base=(word) next_tcp_port;
if (udp_base) *udp_base=(word) next_udp_port;
}
/*
* Checks for bugs when compiling in large model C compiler
*
* Borland C uses a 4K stack by default. In all memory models the
* stack grows down toward the heap.
*
* If you accidentally place tcp_Socket onto the stack (like by making
* it an automatic variable), then you will have already used up that
* whole 4K and then some!
*
* In large model, this will mess up the data space in a major way
* because the stack starts at SS:_stklen, or SS:1000, so you will
* wrap the SP pointer back around to FFFE and start writing over
* the far heap. Yuck.
*
* In small model it usually doesn't kill your application because
* you would have to be down to your last 4K of memory and this is
* not as common.
*
* The solutions: declare your sockets as static, or put them on the
* heap, or bump up your stack size by using the global special variable:
*
* unsigned _stklen = 16536; // set stack to 16 k
*/
static void largecheck(
没有合适的资源?快使用搜索试试~ 我知道了~
com-server.rar_com serv_com-server_ertostcp.lib_server 串口_串口服务器
共144个文件
htm:38个
sht:29个
h:18个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 54 浏览量
2022-09-20
14:56:30
上传
评论
收藏 556KB RAR 举报
温馨提示
这是一个关于串口服务器的源代码,希望对做这方面工作的有所帮助!
资源推荐
资源详情
资源评论
收起资源包目录
com-server.rar_com serv_com-server_ertostcp.lib_server 串口_串口服务器 (144个子文件)
WEB.H.b 34KB
TRANS.H.b 14KB
SETUPDEF.bak 34KB
SETUP.bak 23KB
WATTCP.bak 21KB
TRANS.bak 14KB
SER6.bak 13KB
SERIAL.bak 10KB
delong.bak 7KB
delong.h.bak 6KB
WEB.bak 6KB
web.h.bak 6KB
SERVER.bak 6KB
TIMER.bak 6KB
WORK.bak 480B
linkinfo.btr 41KB
doctodep.btr 26KB
deptodoc.btr 324B
PCTCP.C 93KB
setup.c 18KB
server.c 6KB
GPIO.c 5KB
SYSCFG.CFG 120B
service.cnf 1KB
bots.cnf 323B
botinfs.cnf 146B
structure.cnf 83B
linkinfo.cnf 76B
services.cnf 3B
server.csm 93KB
server.DSW 5KB
web.DSW 212B
server.exe 368KB
LOGO.GIF 3KB
LOGO.GIF 3KB
mcu.gif 1005B
ERTOS.GIF 972B
b1.gif 782B
t2.gif 396B
t1.gif 353B
mcu.gif 220B
logo.gif 208B
b1.gif 200B
t1.gif 200B
t2.gif 200B
SetupDef.h 34KB
web.h 24KB
setup.h 23KB
WATTCP.H 21KB
trans.h 14KB
trans.h 14KB
ser6.h 13KB
ser6.h 13KB
trans1.h 12KB
serial.h 10KB
PCPKT.h 8KB
delong.h 7KB
web.h 6KB
timer.h 6KB
Gpio.h 4KB
timer.h 2KB
TELNETD.H 765B
work.h 473B
CHANGE.HTM 6KB
server.htm 6KB
server_c.htm 5KB
help_c.htm 3KB
help.htm 3KB
left_c.htm 3KB
left.htm 3KB
10pro.htm 2KB
10pro_c.htm 2KB
server.htm 2KB
server_c.htm 2KB
HEADER.HTM 1KB
HEADER.HTM 1KB
left.htm 1KB
left_c.htm 1KB
10pro_c.htm 977B
10pro.htm 975B
stime_c.htm 928B
stime.htm 818B
stime.htm 790B
stime_c.htm 790B
help_c.htm 716B
help.htm 714B
index_c.htm 704B
top.htm 698B
index.htm 687B
email_c.htm 680B
email.htm 678B
stinfo_c.htm 648B
stinfo.htm 646B
stinfo_c.htm 628B
stinfo.htm 626B
email_c.htm 520B
email.htm 485B
index_c.htm 273B
index.htm 269B
top.htm 168B
共 144 条
- 1
- 2
资源评论
weixin_42653672
- 粉丝: 93
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- VIVADO中UART IP核使用
- 【深度学习实际案例解析】深度学习实际案例解析
- 封装swagger组件,提供全新UI以及无状态登录接口调用解决方案
- 小龙坎支局2024年4月渠道积分核对数据.xlam
- onlyoffice搭建及与alist使用的view.html
- Quadcopter-UAV-attitude-estimation-linux常用命令大全demo
- Quadcopter-UAV-attitude-estimation-based-on-数据库课程设计
- pbdlib-python-master.zip
- 43904245495352013_base.apk
- 基于springboot+vue + redis的工作流审批系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功