void malloc_free(malloc_t *heap, void *ptr) { int type = heap->mem_map[(uintptr_t)ptr / RUN_SIZE]; if (ptr == NULL) return; if (type == MM_UNALLOCATED) { /* either large or bad address */ large_free(heap, ptr); } else if (type == MM_SMALL) { small_free(heap, ptr); } else if (type == MM_TINY) { tiny_free(heap, ptr); } else { DBG_ASSERT(0 && "Bad memory type"); } }
void TcpServer_Delete(TcpServer *thiz) { RETURN_IF_FAIL(thiz); TcpServer_Dispose(thiz); tiny_free(thiz); }
void TinyMutex_Delete(TinyMutex *thiz) { RETURN_IF_FAIL(thiz); TinyMutex_Dispose(thiz); tiny_free(thiz); }
void UpnpActionInvoker_Delete(UpnpActionInvoker *thiz) { RETURN_IF_FAIL(thiz); UpnpActionInvoker_Dispose(thiz); tiny_free(thiz); }
void UpnpObjectList_Delete(UpnpObjectList *thiz) { RETURN_IF_FAIL(thiz); UpnpObjectList_Dispose(thiz); tiny_free(thiz); }
void TcpClient_Delete(TcpClient *thiz) { RETURN_IF_FAIL(thiz); TcpClient_Dispose(thiz); tiny_free(thiz); }
static TinyRet udp_join_multicast_group_with_all_ip(int fd, const char *group) { IP_ADAPTER_INFO * pNextAdapter = NULL; IP_ADAPTER_INFO * ipAdaptersInfo = NULL; ULONG infolen = sizeof(IP_ADAPTER_INFO); ipAdaptersInfo = (IP_ADAPTER_INFO *)tiny_malloc(infolen); if (GetAdaptersInfo(ipAdaptersInfo, &infolen) == ERROR_BUFFER_OVERFLOW) { tiny_free(ipAdaptersInfo); ipAdaptersInfo = (IP_ADAPTER_INFO *)tiny_malloc(infolen); } if (GetAdaptersInfo(ipAdaptersInfo, &infolen)) { tiny_free(ipAdaptersInfo); return TINY_RET_E_INTERNAL; } for (pNextAdapter = ipAdaptersInfo; pNextAdapter; pNextAdapter = pNextAdapter->Next) { IP_ADDR_STRING *pNextIp = NULL; for (pNextIp = &(pNextAdapter->IpAddressList); pNextIp; pNextIp = pNextIp->Next) { unsigned long ip = inet_addr(pNextIp->IpAddress.String); if (ip == 0) { break; } LOG_D(TAG, "join MultiGroup ip: %s", pNextIp->IpAddress.String); udp_join_multicast_group_with_ip(fd, group, ip); } } tiny_free(ipAdaptersInfo); return TINY_RET_OK; }
TinyRet TcpClient_StartRecv(TcpClient *thiz, TcpClientReceiveListener listener, void *ctx, uint32_t timeout) { TinyRet ret = TINY_RET_OK; char * buf = NULL; int size = 0; RETURN_VAL_IF_FAIL(thiz, TINY_RET_E_ARG_NULL); RETURN_VAL_IF_FAIL(listener, TINY_RET_E_ARG_NULL); do { if (thiz->status != TCP_CLIENT_CONNECTED) { ret = TINY_RET_E_SOCKET_DISCONNECTED; break; } ret = tiny_tcp_waiting_for_read(thiz->socket_fd, timeout); if (RET_FAILED(ret)) { break; } buf = (char *)tiny_malloc(thiz->recv_buf_size); if (buf == NULL) { ret = TINY_RET_E_OUT_OF_MEMORY; break; } while (true) { memset(buf, 0, thiz->recv_buf_size); size = tiny_tcp_read(thiz->socket_fd, buf, thiz->recv_buf_size); if (size <= 0) { ret = TINY_RET_E_SOCKET_READ; break; } listener(thiz, buf, size, ctx); } } while (false); if (buf != NULL) { tiny_free(buf); } return ret; }