mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-09-28 18:55:02 +00:00
unixsim: enable more warnings and fix the newly found warnings in ports/unix
This commit is contained in:
parent
c2f3fcc72a
commit
12d42c5801
@ -2,6 +2,8 @@
|
||||
#ifndef __LIST_H__
|
||||
#define __LIST_H__
|
||||
|
||||
struct elem;
|
||||
|
||||
struct list {
|
||||
struct elem *first, *last;
|
||||
int size, elems;
|
||||
@ -17,7 +19,6 @@ int list_push(struct list *list, void *data);
|
||||
void *list_pop(struct list *list);
|
||||
void *list_first(struct list *list);
|
||||
int list_elems(struct list *list);
|
||||
int list_elems(struct list *list);
|
||||
void list_delete(struct list *list);
|
||||
int list_remove(struct list *list, void *elem);
|
||||
void list_map(struct list *list, void (* func)(void *arg));
|
||||
|
@ -41,7 +41,7 @@ struct list *
|
||||
list_new(int size)
|
||||
{
|
||||
struct list *list;
|
||||
list = malloc(sizeof(struct list));
|
||||
list = (struct list *)malloc(sizeof(struct list));
|
||||
list->first = list->last = NULL;
|
||||
list->size = size;
|
||||
list->elems = 0;
|
||||
@ -54,7 +54,7 @@ list_push(struct list *list, void *data)
|
||||
struct elem *elem;
|
||||
|
||||
if (list->elems < list->size) {
|
||||
elem = malloc(sizeof(struct elem));
|
||||
elem = (struct elem *)malloc(sizeof(struct elem));
|
||||
elem->data = data;
|
||||
elem->next = NULL;
|
||||
if (list->last != NULL) {
|
||||
|
@ -30,6 +30,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "netif/tapif.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -55,6 +57,8 @@
|
||||
#include "netif/tcpdump.h"
|
||||
#endif /* LWIP_DEBUG && LWIP_TCPDUMP */
|
||||
|
||||
#define IFCONFIG_BIN "/sbin/ifconfig "
|
||||
|
||||
#if defined(linux)
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/if.h>
|
||||
@ -92,9 +96,9 @@ static void
|
||||
low_level_init(struct netif *netif)
|
||||
{
|
||||
struct tapif *tapif;
|
||||
char buf[100];
|
||||
char buf[sizeof(IFCONFIG_ARGS) + sizeof(IFCONFIG_BIN) + 50];
|
||||
|
||||
tapif = netif->state;
|
||||
tapif = (struct tapif *)netif->state;
|
||||
|
||||
/* Obtain MAC address from network interface. */
|
||||
|
||||
@ -131,7 +135,7 @@ low_level_init(struct netif *netif)
|
||||
}
|
||||
#endif /* Linux */
|
||||
|
||||
snprintf(buf, sizeof(buf), "/sbin/ifconfig " IFCONFIG_ARGS,
|
||||
sprintf(buf, IFCONFIG_BIN IFCONFIG_ARGS,
|
||||
ip4_addr1(&(netif->gw)),
|
||||
ip4_addr2(&(netif->gw)),
|
||||
ip4_addr3(&(netif->gw)),
|
||||
@ -161,7 +165,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
|
||||
char *bufptr;
|
||||
struct tapif *tapif;
|
||||
|
||||
tapif = netif->state;
|
||||
tapif = (struct tapif *)netif->state;
|
||||
#if 0
|
||||
if(((double)rand()/(double)RAND_MAX) < 0.2) {
|
||||
printf("drop output\n");
|
||||
@ -245,8 +249,8 @@ tapif_thread(void *arg)
|
||||
fd_set fdset;
|
||||
int ret;
|
||||
|
||||
netif = arg;
|
||||
tapif = netif->state;
|
||||
netif = (struct netif *)arg;
|
||||
tapif = (struct tapif *)netif->state;
|
||||
|
||||
while(1) {
|
||||
FD_ZERO(&fdset);
|
||||
@ -282,7 +286,7 @@ tapif_input(struct netif *netif)
|
||||
struct pbuf *p;
|
||||
|
||||
|
||||
tapif = netif->state;
|
||||
tapif = (struct tapif *)netif->state;
|
||||
|
||||
p = low_level_input(tapif);
|
||||
|
||||
@ -290,7 +294,7 @@ tapif_input(struct netif *netif)
|
||||
LWIP_DEBUGF(TAPIF_DEBUG, ("tapif_input: low_level_input returned NULL\n"));
|
||||
return;
|
||||
}
|
||||
ethhdr = p->payload;
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
|
||||
switch(htons(ethhdr->type)) {
|
||||
/* IP or ARP packet? */
|
||||
@ -328,9 +332,10 @@ tapif_init(struct netif *netif)
|
||||
{
|
||||
struct tapif *tapif;
|
||||
|
||||
tapif = mem_malloc(sizeof(struct tapif));
|
||||
if (!tapif)
|
||||
tapif = (struct tapif *)mem_malloc(sizeof(struct tapif));
|
||||
if (!tapif) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
netif->state = tapif;
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
|
@ -74,8 +74,9 @@ tcpdump(struct pbuf *p)
|
||||
return;
|
||||
}
|
||||
#ifdef IPv4
|
||||
iphdr = p->payload;
|
||||
iphdr = (struct ip_hdr *)p->payload;
|
||||
switch (IPH_PROTO(iphdr)) {
|
||||
#if LWIP_TCP
|
||||
case IP_PROTO_TCP:
|
||||
tcphdr = (struct tcp_hdr *)((char *)iphdr + IP_HLEN);
|
||||
|
||||
@ -144,6 +145,7 @@ tcpdump(struct pbuf *p)
|
||||
|
||||
pbuf_header(p, IP_HLEN);
|
||||
break;
|
||||
#endif /* LWIP_TCP */
|
||||
|
||||
#if LWIP_UDP
|
||||
case IP_PROTO_UDP:
|
||||
@ -182,6 +184,9 @@ tcpdump(struct pbuf *p)
|
||||
pbuf_header(p, IP_HLEN);
|
||||
break;
|
||||
#endif /* LWIP_UDP */
|
||||
default:
|
||||
LWIP_DEBUGF(TCPDUMP_DEBUG, ("unhandled IP protocol: %d\n", (int)IPH_PROTO(iphdr)));
|
||||
break;
|
||||
|
||||
}
|
||||
#endif /* IPv4 */
|
||||
|
@ -30,6 +30,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "netif/tunif.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -58,6 +60,8 @@
|
||||
#define TUNIF_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#define IFCONFIG_CALL "/sbin/ifconfig tun0 inet %d.%d.%d.%d %d.%d.%d.%d"
|
||||
|
||||
struct tunif {
|
||||
/* Add whatever per-interface state that is needed here. */
|
||||
int fd;
|
||||
@ -75,9 +79,9 @@ static void
|
||||
low_level_init(struct netif *netif)
|
||||
{
|
||||
struct tunif *tunif;
|
||||
char buf[100];
|
||||
char buf[sizeof(IFCONFIG_CALL) + 50];
|
||||
|
||||
tunif = netif->state;
|
||||
tunif = (struct tunif *)netif->state;
|
||||
|
||||
/* Obtain MAC address from network interface. */
|
||||
|
||||
@ -89,7 +93,7 @@ low_level_init(struct netif *netif)
|
||||
perror("tunif_init");
|
||||
exit(1);
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "/sbin/ifconfig tun0 inet %d.%d.%d.%d %d.%d.%d.%d",
|
||||
sprintf(buf, IFCONFIG_CALL,
|
||||
ip4_addr1(&(netif->gw)),
|
||||
ip4_addr2(&(netif->gw)),
|
||||
ip4_addr3(&(netif->gw)),
|
||||
@ -121,10 +125,12 @@ low_level_output(struct tunif *tunif, struct pbuf *p)
|
||||
struct pbuf *q;
|
||||
char buf[1500];
|
||||
char *bufptr;
|
||||
int rnd_val;
|
||||
|
||||
/* initiate transfer(); */
|
||||
|
||||
if (((double)rand()/(double)RAND_MAX) < 0.4) {
|
||||
rnd_val = rand();
|
||||
if (((double)rnd_val/(double)RAND_MAX) < 0.4) {
|
||||
printf("drop\n");
|
||||
return ERR_OK;
|
||||
}
|
||||
@ -137,7 +143,7 @@ low_level_output(struct tunif *tunif, struct pbuf *p)
|
||||
time. The size of the data in each pbuf is kept in the ->len
|
||||
variable. */
|
||||
/* send data from(q->payload, q->len); */
|
||||
bcopy(q->payload, bufptr, q->len);
|
||||
memcpy(q->payload, bufptr, q->len);
|
||||
bufptr += q->len;
|
||||
}
|
||||
|
||||
@ -186,7 +192,7 @@ low_level_input(struct tunif *tunif)
|
||||
available data in the pbuf is given by the q->len
|
||||
variable. */
|
||||
/* read data into(q->payload, q->len); */
|
||||
bcopy(bufptr, q->payload, q->len);
|
||||
memcpy(bufptr, q->payload, q->len);
|
||||
bufptr += q->len;
|
||||
}
|
||||
/* acknowledge that packet has been read(); */
|
||||
@ -205,8 +211,8 @@ tunif_thread(void *arg)
|
||||
fd_set fdset;
|
||||
int ret;
|
||||
|
||||
netif = arg;
|
||||
tunif = netif->state;
|
||||
netif = (struct netif *)arg;
|
||||
tunif = (struct tunif *)netif->state;
|
||||
|
||||
while (1) {
|
||||
FD_ZERO(&fdset);
|
||||
@ -240,7 +246,7 @@ tunif_output(struct netif *netif, struct pbuf *p,
|
||||
struct tunif *tunif;
|
||||
LWIP_UNUSED_ARG(ipaddr);
|
||||
|
||||
tunif = netif->state;
|
||||
tunif = (struct tunif *)netif->state;
|
||||
|
||||
return low_level_output(tunif, p);
|
||||
|
||||
@ -263,7 +269,7 @@ tunif_input(struct netif *netif)
|
||||
struct pbuf *p;
|
||||
|
||||
|
||||
tunif = netif->state;
|
||||
tunif = (struct tunif *)netif->state;
|
||||
|
||||
p = low_level_input(tunif);
|
||||
|
||||
@ -296,9 +302,10 @@ tunif_init(struct netif *netif)
|
||||
{
|
||||
struct tunif *tunif;
|
||||
|
||||
tunif = mem_malloc(sizeof(struct tunif));
|
||||
if (!tunif)
|
||||
tunif = (struct tunif *)mem_malloc(sizeof(struct tunif));
|
||||
if (!tunif) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
netif->state = tunif;
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
|
@ -81,7 +81,7 @@ struct unixif {
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static int
|
||||
unix_socket_client(char *name)
|
||||
unix_socket_client(const char *name)
|
||||
{
|
||||
int fd, len;
|
||||
struct sockaddr_un unix_addr;
|
||||
@ -137,7 +137,7 @@ unix_socket_client(char *name)
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static int
|
||||
unix_socket_server(char *name)
|
||||
unix_socket_server(const char *name)
|
||||
{
|
||||
int fd, len;
|
||||
struct sockaddr_un unix_addr;
|
||||
@ -189,12 +189,12 @@ unixif_input_handler(void *data)
|
||||
{
|
||||
struct netif *netif;
|
||||
struct unixif *unixif;
|
||||
char buf[4096], *bufptr;
|
||||
char buf[1532], *bufptr;
|
||||
int len, plen, rlen;
|
||||
struct pbuf *p, *q;
|
||||
|
||||
netif = data;
|
||||
unixif = netif->state;
|
||||
netif = (struct netif *)data;
|
||||
unixif = (struct unixif *)netif->state;
|
||||
|
||||
len = read(unixif->fd, &plen, sizeof(int));
|
||||
if (len == -1) {
|
||||
@ -248,8 +248,8 @@ unixif_thread(void *arg)
|
||||
|
||||
LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_thread: started.\n"));
|
||||
|
||||
netif = arg;
|
||||
unixif = netif->state;
|
||||
netif = (struct netif *)arg;
|
||||
unixif = (struct unixif *)netif->state;
|
||||
|
||||
|
||||
while (1) {
|
||||
@ -268,8 +268,8 @@ unixif_thread2(void *arg)
|
||||
|
||||
LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_thread2: started.\n"));
|
||||
|
||||
netif = arg;
|
||||
unixif = netif->state;
|
||||
netif = (struct netif *)arg;
|
||||
unixif = (struct unixif *)netif->state;
|
||||
|
||||
while (1) {
|
||||
FD_ZERO(&fdset);
|
||||
@ -288,9 +288,11 @@ unixif_output(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
|
||||
{
|
||||
struct unixif *unixif;
|
||||
struct unixif_buf *buf;
|
||||
unixif = netif->state;
|
||||
LWIP_UNUSED_ARG(ipaddr);
|
||||
|
||||
buf = malloc(sizeof(struct unixif_buf));
|
||||
unixif = (struct unixif *)netif->state;
|
||||
|
||||
buf = (struct unixif_buf *)malloc(sizeof(struct unixif_buf));
|
||||
buf->p = p;
|
||||
buf->len = p->len;
|
||||
buf->tot_len = p->tot_len;
|
||||
@ -343,15 +345,15 @@ unixif_output_timeout(void *arg)
|
||||
struct unixif *unixif;
|
||||
char *data;
|
||||
|
||||
netif = arg;
|
||||
unixif = netif->state;
|
||||
netif = (struct netif *)arg;
|
||||
unixif = (struct unixif *)netif->state;
|
||||
|
||||
LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_output_timeout\n"));
|
||||
|
||||
/* buf = unixif->q[0];
|
||||
unixif->q[0] = unixif->q[1];
|
||||
unixif->q[1] = NULL;*/
|
||||
buf = list_pop(unixif->q);
|
||||
buf = (struct unixif_buf *)list_pop(unixif->q);
|
||||
|
||||
p = buf->p;
|
||||
|
||||
@ -369,7 +371,7 @@ unixif_output_timeout(void *arg)
|
||||
LWIP_DEBUGF(UNIXIF_DEBUG, ("p->len!\n"));
|
||||
abort();
|
||||
}
|
||||
data = malloc(p->tot_len);
|
||||
data = (char *)malloc(p->tot_len);
|
||||
|
||||
i = 0;
|
||||
for(q = p; q != NULL; q = q->next) {
|
||||
@ -430,9 +432,10 @@ unixif_init_server(struct netif *netif)
|
||||
}
|
||||
LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_server: fd %d\n", fd));
|
||||
|
||||
unixif = malloc(sizeof(struct unixif));
|
||||
if (!unixif)
|
||||
unixif = (struct unixif *)malloc(sizeof(struct unixif));
|
||||
if (!unixif) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
netif->state = unixif;
|
||||
netif->name[0] = 'u';
|
||||
netif->name[1] = 'n';
|
||||
@ -463,9 +466,10 @@ err_t
|
||||
unixif_init_client(struct netif *netif)
|
||||
{
|
||||
struct unixif *unixif;
|
||||
unixif = malloc(sizeof(struct unixif));
|
||||
if (!unixif)
|
||||
unixif = (struct unixif *)malloc(sizeof(struct unixif));
|
||||
if (!unixif) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
netif->state = unixif;
|
||||
netif->name[0] = 'u';
|
||||
netif->name[1] = 'n';
|
||||
|
@ -35,7 +35,16 @@ CC=gcc
|
||||
#To compile for linux: make ARCH=linux
|
||||
#To compile for cygwin: make ARCH=cygwin
|
||||
ARCH=unix
|
||||
CFLAGS=-g -Wall -D$(ARCH) -DIPv4 -DLWIP_DEBUG -pedantic -Werror
|
||||
CFLAGS=-g -Wall -D$(ARCH) -DIPv4 -DLWIP_DEBUG -pedantic -Werror \
|
||||
-Wparentheses -Wsequence-point -Wswitch-default \
|
||||
-Wextra -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast \
|
||||
-Wc++-compat -Wwrite-strings -Wold-style-definition \
|
||||
-Wmissing-prototypes -Wredundant-decls -Wnested-externs
|
||||
# not used for now but interesting:
|
||||
# -Wpacked
|
||||
# -Wunreachable-code
|
||||
# -ansi
|
||||
# -std=c89
|
||||
LDFLAGS=-lpthread -lutil
|
||||
CONTRIBDIR=../../../..
|
||||
LWIPARCH=$(CONTRIBDIR)/ports/unix
|
||||
|
@ -109,7 +109,7 @@ static struct option longopts[] = {
|
||||
|
||||
static void init_netifs(void);
|
||||
|
||||
void usage(void)
|
||||
static void usage(void)
|
||||
{
|
||||
unsigned char i;
|
||||
|
||||
@ -122,6 +122,7 @@ void usage(void)
|
||||
static void
|
||||
tcp_debug_timeout(void *data)
|
||||
{
|
||||
LWIP_UNUSED_ARG(data);
|
||||
#if TCP_DEBUG
|
||||
tcp_debug_print_pcbs();
|
||||
#endif /* TCP_DEBUG */
|
||||
@ -132,7 +133,7 @@ static void
|
||||
tcpip_init_done(void *arg)
|
||||
{
|
||||
sys_sem_t *sem;
|
||||
sem = arg;
|
||||
sem = (sys_sem_t *)arg;
|
||||
|
||||
init_netifs();
|
||||
|
||||
@ -260,7 +261,7 @@ ping_send(int s, ip_addr_t *addr)
|
||||
struct icmp_echo_hdr *iecho;
|
||||
struct sockaddr_in to;
|
||||
|
||||
if (!(iecho = malloc(sizeof(struct icmp_echo_hdr))))
|
||||
if (!(iecho = (struct icmp_echo_hdr *)malloc(sizeof(struct icmp_echo_hdr))))
|
||||
return;
|
||||
|
||||
ICMPH_TYPE_SET(iecho,ICMP_ECHO);
|
||||
@ -285,6 +286,7 @@ ping_recv(int s, ip_addr_t *addr)
|
||||
socklen_t fromlen;
|
||||
int len;
|
||||
struct sockaddr_in from;
|
||||
LWIP_UNUSED_ARG(addr);
|
||||
|
||||
len = lwip_recvfrom(s, buf,sizeof(buf),0,(struct sockaddr*)&from,&fromlen);
|
||||
|
||||
@ -295,6 +297,7 @@ static void
|
||||
ping_thread(void *arg)
|
||||
{
|
||||
int s;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
|
||||
return;
|
||||
@ -379,6 +382,7 @@ main_thread(void *arg)
|
||||
#if PPP_SUPPORT
|
||||
sio_fd_t ppp_sio;
|
||||
#endif
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
netif_init();
|
||||
|
||||
|
@ -67,6 +67,7 @@ unsigned char debug_flags;
|
||||
static void
|
||||
tcp_timeout(void *data)
|
||||
{
|
||||
LWIP_UNUSED_ARG(data);
|
||||
#if TCP_DEBUG
|
||||
tcp_debug_print_pcbs();
|
||||
#endif /* TCP_DEBUG */
|
||||
@ -80,7 +81,7 @@ tcpip_init_done(void *arg)
|
||||
{
|
||||
ip_addr_t ipaddr, netmask, gw;
|
||||
sys_sem_t *sem;
|
||||
sem = arg;
|
||||
sem = (sys_sem_t *)arg;
|
||||
|
||||
IP4_ADDR(&gw, 192,168,1,1);
|
||||
IP4_ADDR(&ipaddr, 192,168,1,2);
|
||||
@ -108,6 +109,7 @@ static void
|
||||
main_thread(void *arg)
|
||||
{
|
||||
sys_sem_t sem;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
if(sys_sem_new(&sem, 0) != ERR_OK) {
|
||||
LWIP_ASSERT("Failed to create semaphore", 0);
|
||||
@ -125,7 +127,7 @@ main_thread(void *arg)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(void)
|
||||
{
|
||||
#ifdef PERF
|
||||
perf_init("/tmp/client.perf");
|
||||
|
@ -69,6 +69,7 @@ unsigned char debug_flags;
|
||||
static void
|
||||
tcp_timeout(void *data)
|
||||
{
|
||||
LWIP_UNUSED_ARG(data);
|
||||
#if TCP_DEBUG
|
||||
tcp_debug_print_pcbs();
|
||||
#endif /* TCP_DEBUG */
|
||||
@ -84,7 +85,7 @@ tcpip_init_done(void *arg)
|
||||
{
|
||||
ip_addr_t ipaddr, netmask, gw;
|
||||
sys_sem_t *sem;
|
||||
sem = arg;
|
||||
sem = (sys_sem_t *)arg;
|
||||
|
||||
IP4_ADDR(&gw, 192,168,0,1);
|
||||
IP4_ADDR(&ipaddr, 192,168,0,2);
|
||||
@ -123,6 +124,7 @@ static void
|
||||
main_thread(void *arg)
|
||||
{
|
||||
sys_sem_t sem;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
if(sys_sem_new(&sem, 0) != ERR_OK) {
|
||||
LWIP_ASSERT("Failed to create semaphore", 0);
|
||||
@ -139,7 +141,7 @@ main_thread(void *arg)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(void)
|
||||
{
|
||||
#ifdef PERF
|
||||
perf_init("/tmp/client.perf");
|
||||
|
@ -111,7 +111,7 @@ introduce_thread(pthread_t id)
|
||||
{
|
||||
struct sys_thread *thread;
|
||||
|
||||
thread = malloc(sizeof(struct sys_thread));
|
||||
thread = (struct sys_thread *)malloc(sizeof(struct sys_thread));
|
||||
|
||||
if (thread != NULL) {
|
||||
pthread_mutex_lock(&threads_mutex);
|
||||
@ -125,7 +125,7 @@ introduce_thread(pthread_t id)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
sys_thread_t
|
||||
sys_thread_new(char *name, void (* function)(void *arg), void *arg, int stacksize, int prio)
|
||||
sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio)
|
||||
{
|
||||
int code;
|
||||
pthread_t tmp;
|
||||
@ -158,7 +158,7 @@ sys_mbox_new(struct sys_mbox **mb, int size)
|
||||
struct sys_mbox *mbox;
|
||||
LWIP_UNUSED_ARG(size);
|
||||
|
||||
mbox = malloc(sizeof(struct sys_mbox));
|
||||
mbox = (struct sys_mbox *)malloc(sizeof(struct sys_mbox));
|
||||
if (mbox == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
@ -351,7 +351,7 @@ sys_sem_new_internal(u8_t count)
|
||||
{
|
||||
struct sys_sem *sem;
|
||||
|
||||
sem = malloc(sizeof(struct sys_sem));
|
||||
sem = (struct sys_sem *)malloc(sizeof(struct sys_sem));
|
||||
if (sem != NULL) {
|
||||
sem->c = count;
|
||||
pthread_cond_init(&(sem->cond), NULL);
|
||||
@ -378,12 +378,11 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u32_t timeout)
|
||||
unsigned long sec, usec;
|
||||
struct timeval rtime1, rtime2;
|
||||
struct timespec ts;
|
||||
struct timezone tz;
|
||||
int retval;
|
||||
|
||||
if (timeout > 0) {
|
||||
/* Get a timestamp and add the timeout value. */
|
||||
gettimeofday(&rtime1, &tz);
|
||||
gettimeofday(&rtime1, NULL);
|
||||
sec = rtime1.tv_sec;
|
||||
usec = rtime1.tv_usec;
|
||||
usec += timeout % 1000 * 1000;
|
||||
@ -398,7 +397,7 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u32_t timeout)
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
} else {
|
||||
/* Calculate for how long we waited for the cond. */
|
||||
gettimeofday(&rtime2, &tz);
|
||||
gettimeofday(&rtime2, NULL);
|
||||
tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 +
|
||||
(rtime2.tv_usec - rtime1.tv_usec) / 1000;
|
||||
|
||||
@ -482,9 +481,8 @@ u32_t
|
||||
sys_now(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
u32_t sec, usec, msec;
|
||||
gettimeofday(&tv, &tz);
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
sec = (u32_t)(tv.tv_sec - starttime.tv_sec);
|
||||
usec = (u32_t)(tv.tv_usec - starttime.tv_usec);
|
||||
@ -494,10 +492,9 @@ sys_now(void)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
sys_init()
|
||||
sys_init(void)
|
||||
{
|
||||
struct timezone tz;
|
||||
gettimeofday(&starttime, &tz);
|
||||
gettimeofday(&starttime, NULL);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if SYS_LIGHTWEIGHT_PROT
|
||||
|
Loading…
Reference in New Issue
Block a user