资源简介
linux下对coap服务器和客户端的仿真程序,适合初学者理解coap协议
代码片段和文件信息
/* async.c -- state management for asynchronous messages
*
* Copyright (C) 20102011 Olaf Bergmann
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
/**
* @file async.c
* @brief state management for asynchronous messages
*/
#ifndef WITHOUT_ASYNC
#include “config.h“
#include “utlist.h“
#include “mem.h“
#include “debug.h“
#include “async.h“
coap_async_state_t *
coap_register_async(coap_context_t *context coap_address_t *peer
coap_pdu_t *request unsigned char flags void *data) {
coap_async_state_t *s;
coap_opt_iterator_t opt_iter;
coap_tid_t id;
coap_transaction_id(peer request &id);
LL_SEARCH_SCALAR(context->async_statesidid);
if (s != NULL) {
/* We must return NULL here as the caller must know that he is
* responsible for releasing @p data. */
debug(“asynchronous state for transaction %d already registered\n“ id);
return NULL;
}
/* store information for handling the asynchronous task */
s = (coap_async_state_t *)coap_malloc(sizeof(coap_async_state_t) +
request->hdr->token_length);
if (!s) {
coap_log(LOG_CRIT “coap_register_async: insufficient memory\n“);
return NULL;
}
memset(s 0 sizeof(coap_async_state_t) + request->hdr->token_length);
/* set COAP_ASYNC_CONFIRM according to request‘s type */
s->flags = flags & ~COAP_ASYNC_CONFIRM;
if (request->hdr->type == COAP_MESSAGE_CON)
s->flags |= COAP_ASYNC_CONFIRM;
s->appdata = data;
memcpy(&s->peer peer sizeof(coap_address_t));
if (request->hdr->token_length) {
s->tokenlen = request->hdr->token_length;
memcpy(s->token request->hdr->token request->hdr->token_length);
}
memcpy(&s->id &id sizeof(coap_tid_t));
coap_touch_async(s);
LL_PREPEND(context->async_state s);
return s;
}
coap_async_state_t *
coap_find_async(coap_context_t *context coap_tid_t id) {
coap_async_state_t *tmp;
LL_SEARCH_SCALAR(context->async_statetmpidid);
return tmp;
}
int
coap_remove_async(coap_context_t *context coap_tid_t id
coap_async_state_t **s) {
coap_async_state_t *tmp = coap_find_async(context id);
if (tmp)
LL_DELETE(context->async_statetmp);
*s = tmp;
return tmp != NULL;
}
void
coap_free_async(coap_async_state_t *s) {
if (s && (s->flags & COAP_ASYNC_RELEASE_DATA) != 0)
coap_free(s->appdata);
coap_free(s);
}
#else
void does_not_exist(); /* make some compilers happy */
#endif /* WITHOUT_ASYNC */
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-02-26 00:28 libcoap-4.0.1\
文件 2968 2013-01-24 23:57 libcoap-4.0.1\ChangeLog
文件 1315 2013-01-24 23:57 libcoap-4.0.1\LICENSE.BSD
文件 15220 2013-01-24 23:57 libcoap-4.0.1\LICENSE.GPL
文件 2020 2013-01-24 23:57 libcoap-4.0.1\Makefile.in
文件 1010 2013-01-24 23:57 libcoap-4.0.1\README
文件 3510 2013-01-24 23:57 libcoap-4.0.1\address.h
文件 2508 2013-01-24 23:57 libcoap-4.0.1\async.c
文件 5172 2013-01-24 23:57 libcoap-4.0.1\async.h
文件 2024 2013-01-24 23:57 libcoap-4.0.1\bits.h
文件 2923 2013-01-24 23:57 libcoap-4.0.1\block.c
文件 4451 2013-01-24 23:57 libcoap-4.0.1\block.h
文件 535 2013-01-24 23:57 libcoap-4.0.1\coap.h
文件 1671 2013-01-24 23:57 libcoap-4.0.1\coap_list.c
文件 1294 2013-01-24 23:57 libcoap-4.0.1\coap_list.h
文件 1850 2013-01-24 23:57 libcoap-4.0.1\coap_time.h
文件 3714 2013-01-24 23:57 libcoap-4.0.1\config.h
文件 3482 2013-01-24 23:57 libcoap-4.0.1\config.h.in
文件 154909 2013-01-24 23:57 libcoap-4.0.1\configure
文件 2522 2013-01-24 23:57 libcoap-4.0.1\configure.in
文件 8420 2013-01-24 23:57 libcoap-4.0.1\debug.c
文件 1651 2013-01-24 23:57 libcoap-4.0.1\debug.h
目录 0 2013-02-26 00:28 libcoap-4.0.1\doc\
文件 65441 2013-01-24 23:57 libcoap-4.0.1\doc\Doxyfile.in
文件 1253 2013-01-24 23:57 libcoap-4.0.1\doc\Makefile.in
目录 0 2013-02-26 00:28 libcoap-4.0.1\doc\html\
文件 17884 2013-01-24 23:57 libcoap-4.0.1\doc\html\address_8h.html
文件 26461 2013-01-24 23:57 libcoap-4.0.1\doc\html\address_8h_source.html
文件 13245 2013-01-24 23:57 libcoap-4.0.1\doc\html\annotated.html
文件 9854 2013-01-24 23:57 libcoap-4.0.1\doc\html\async_8c.html
文件 25804 2013-01-24 23:57 libcoap-4.0.1\doc\html\async_8c_source.html
............此处省略99个文件信息
相关资源
- 改变树控件背景颜色的VC源代码
- 线积分卷积LIC源代码
- 英汉汉英字典C源代码
- STM32雕刻机、CNC源代码
- MSP430单片机的实时多任务操作系统c源
- 偷窥者远程控制软件的VC源代码
- AES算法标准C程序源代码
- 车牌识别VC源代码
- dspic源代码
- e语言zfb监控pc源代码
- pesq算法源代码c源代码
- Windows服务程序VC源代码
- HZK16字模提取C源代码
- lwm2m协议开发文档
- 论文研究-基于CoAP协议的智能家居功耗
- RFC7252-受限应用协议CoAP协议中文版.
- UDP 文件传输vc源代码
- hurst指数 C源代码
- C源代码:显示指定字符在指定字体中对
- 3DES和基于PBOC的MAC源代码 C
- 常用数值计算方法c源代码实现
- ITE_V12.4_Update 嵌入式控制器EC源代码
- RSA加密算法的C源代码
- vigenere密码的无密钥破解方法c源代码
- linux下实现自动查找U盘,识别U盘,判
- 二维码生成的C源代码(QRCODE)
评论
共有 条评论