MCPcopy Create free account
hub / github.com/SIPp/sipp / alloc_socketbuf

Function alloc_socketbuf

src/socket.cpp:1646–1672  ·  view source on GitHub ↗

Allocate a socket buffer. */

Source from the content-addressed store, hash-verified

1644
1645/* Allocate a socket buffer. */
1646struct socketbuf *alloc_socketbuf(char *buffer, size_t size, int copy, struct sockaddr_storage *dest)
1647{
1648 struct socketbuf *socketbuf;
1649
1650 socketbuf = (struct socketbuf *)malloc(sizeof(struct socketbuf));
1651 if (!socketbuf) {
1652 ERROR("Could not allocate socket buffer!");
1653 }
1654 memset(socketbuf, 0, sizeof(struct socketbuf));
1655 if (copy) {
1656 socketbuf->buf = (char *)malloc(size);
1657 if (!socketbuf->buf) {
1658 ERROR("Could not allocate socket buffer data!");
1659 }
1660 memcpy(socketbuf->buf, buffer, size);
1661 } else {
1662 socketbuf->buf = buffer;
1663 }
1664 socketbuf->len = size;
1665 socketbuf->offset = 0;
1666 if (dest) {
1667 memcpy(&socketbuf->addr, dest, sizeof(*dest));
1668 }
1669 socketbuf->next = nullptr;
1670
1671 return socketbuf;
1672}
1673
1674/* Free a poll buffer. */
1675void free_socketbuf(struct socketbuf *socketbuf)

Callers 2

emptyMethod · 0.85
buffer_writeMethod · 0.85

Calls 1

ERRORFunction · 0.85

Tested by

no test coverage detected