Note that there are some explanatory texts on larger screens.

plurals
  1. POI have a dynamic library, how to know if it calls malloc during run-time?
    primarykey
    data
    text
    <p>I need to do networking in uCsimm, Motorola Dragon Ball. As I'm running uClinux with RTAI patch, and I need real-time performance, therefore all malloc and its friends are undesirable. I have the following piece of code for socket dynamic library. How to know that it calls malloc during run-time? When I compiled in cygwin on Windows, I used cygwin and found that it uses malloc, calloc, realloc &amp; free. How to find out on Ubuntu/Linux which functions are called during run-time? Thanks in advance!</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;sys/time.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/socket.h&gt; #include &lt;netinet/in.h&gt; #include &lt;errno.h&gt; #include &lt;unistd.h&gt; #include &lt;arpa/inet.h&gt; /* BUFFER_LEN is 4096 bytes */ #define BUFFER_LEN 4096 /* receiver port number */ #define RECEIVERPORT 2009 /* Variable and structure definitions. */ int receiver_socket_d, client_socket_d, ret_val; unsigned int length = sizeof (unsigned int); int totalcnt = 0, on = 1; char temp; char buffer[BUFFER_LEN]; struct sockaddr_in serveraddr; struct sockaddr_in their_addr; fd_set read_fd; struct timeval timeout; int receiver_setup() { timeout.tv_sec = 5; timeout.tv_usec = 0; /* The socket() function returns a socket descriptor */ /* representing an endpoint. The statement also */ /* identifies that the INET (Internet Protocol) */ /* address family with the TCP transport (SOCK_STREAM) */ /* will be used for this socket. */ /************************************************/ /* Get a socket descriptor */ if ((receiver_socket_d = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) { //perror("receiver-socket() error"); /* Just exit */ exit(-1); } else //printf("receiver-socket() is OK\n"); /* The setsockopt() function is used to allow */ /* the local address to be reused when the server */ /* is restarted before the required wait time */ /* expires. */ /***********************************************/ /* Allow socket descriptor to be reusable */ if ((ret_val = setsockopt(receiver_socket_d, SOL_SOCKET, SO_REUSEADDR, (char *) &amp; on, sizeof (on))) &lt; 0) { //perror("receiver-setsockopt() error"); close(receiver_socket_d); exit(-1); } else //printf("receiver-setsockopt() is OK\n"); /* bind to an address */ memset(&amp;serveraddr, 0x00, sizeof (struct sockaddr_in)); serveraddr.sin_family = AF_INET; serveraddr.sin_port = htons(RECEIVERPORT); serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); //printf("Using %s, listening at %d\n", inet_ntoa(serveraddr.sin_addr), RECEIVERPORT); /* After the socket descriptor is created, a bind() */ /* function gets a unique name for the socket. */ /* In this example, the user sets the */ /* s_addr to zero, which allows the system to */ /* connect to any client that used port 3005. */ if ((ret_val = bind(receiver_socket_d, (struct sockaddr *) &amp; serveraddr, sizeof (serveraddr))) &lt; 0) { //perror("receiver-bind() error"); /* Close the socket descriptor */ close(receiver_socket_d); /* and just exit */ exit(-1); } else //printf("receiver-bind() is OK\n"); /* The listen() function allows the server to accept */ /* incoming client connections. In this example, */ /* the backlog is set to 10. This means that the */ /* system can queue up to 10 connection requests before */ /* the system starts rejecting incoming requests.*/ /*************************************************/ /* Up to 10 clients can be queued */ if ((ret_val = listen(receiver_socket_d, 10)) &lt; 0) { //perror("receiver-listen() error"); close(receiver_socket_d); exit(-1); } else //printf("receiver-Ready for client connection...\n"); return 0; } int receiver_wait() { /* The server will accept a connection request */ /* with this accept() function, provided the */ /* connection request does the following: */ /* - Is part of the same address family */ /* - Uses streams sockets (TCP) */ /* - Attempts to connect to the specified port */ /***********************************************/ /* accept() the incoming connection request. */ unsigned int sin_size = sizeof (struct sockaddr_in); if ((client_socket_d = accept(receiver_socket_d, (struct sockaddr *) &amp; their_addr, &amp;sin_size)) &lt; 0) { //perror("receiver-accept() error"); close(receiver_socket_d); exit(-1); } else //printf("receiver-accept() is OK\n"); /*client IP*/ //printf("receiver-new socket, client_socket_d is OK...\n"); //printf("Got connection from client: %s\n", inet_ntoa(their_addr.sin_addr)); /* The select() function allows the process to */ /* wait for an event to occur and to wake up */ /* the process when the event occurs. In this */ /* example, the system notifies the process */ /* only when data is available to read. */ /***********************************************/ /* Wait for up to 15 seconds on */ /* select() for data to be read. */ FD_ZERO(&amp;read_fd); FD_SET(client_socket_d, &amp;read_fd); ret_val = select(client_socket_d + 1, &amp;read_fd, NULL, NULL, &amp;timeout); return 0; }; int receiver_read() { buffer[0] = 0; buffer[1] = 0; totalcnt = 0; if ((ret_val == 1) &amp;&amp; (FD_ISSET(client_socket_d, &amp;read_fd))) { /* Read data from the client. */ while ( (totalcnt &lt; BUFFER_LEN) &amp;&amp; (ret_val &gt; 0) ) { /* When select() indicates that there is data */ /* available, use the read() function to read */ /* 4096 bytes of the string that the */ /* client sent. */ /***********************************************/ /* read() from client */ ret_val = read(client_socket_d, &amp;buffer[totalcnt], (BUFFER_LEN - totalcnt)); //printf("Received data from client: %s\n\n", buffer); if (ret_val &lt; 0) { //perror("receiver-read() error"); close(receiver_socket_d); close(client_socket_d); exit(-1); } else if (ret_val == 0) { //printf("Client program has issued a close()\n"); //close(receiver_socket_d); //close(client_socket_d); //exit(-1); } else { totalcnt += ret_val; //printf("receiver-read() is OK\n"); } } } else if (ret_val &lt; 0) { //perror("receiver-select() error"); close(receiver_socket_d); close(client_socket_d); exit(-1); } else {/* ret_val == 0 */ //printf("receiver-select() timed out.\n"); close(client_socket_d); receiver_wait(); //close(receiver_socket_d); //exit(-1); } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload