Skip to content

Commit

Permalink
Refactor tube_manager to a separate file, add support for timers and …
Browse files Browse the repository at this point in the history
…signals
  • Loading branch information
hildjj committed May 22, 2015
1 parent cd5bb1a commit a7b2938
Show file tree
Hide file tree
Showing 29 changed files with 3,455 additions and 1,040 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# top level build file for the SPUDlib

## prepare CMAKE
cmake_minimum_required ( VERSION 3.0.0 )
cmake_minimum_required ( VERSION 3.2.0 )

set ( SPUDLIB_VERSION_MAJOR 0 CACHE STRING "Project major version number")
set ( SPUDLIB_VERSION_MINOR "3" CACHE STRING "Project minor version number" )
set ( SPUDLIB_VERSION_MAJOR "0" CACHE STRING "Project major version number")
set ( SPUDLIB_VERSION_MINOR "4" CACHE STRING "Project minor version number" )
set ( SPUDLIB_VERSION_PATCH "0" CACHE STRING "Project patch version number" )
mark_as_advanced(SPUDLIB_VERSION_MAJOR SPUDLIB_VERSION_MINOR SPUDLIB_VERSION_PATCH)

Expand Down Expand Up @@ -90,6 +90,9 @@ if ( verbose )
set ( CMAKE_VERBOSE_MAKEFILE ON )
endif ()

find_program( MEMORYCHECK_COMMAND valgrind )
set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" )

install (FILES AUTHORS LICENSE README.md DESTINATION .)

## setup packaging
Expand Down Expand Up @@ -148,6 +151,7 @@ ExternalProject_Add(
GIT_REPOSITORY https://github.com/hildjj/cn-cbor.git
CMAKE_ARGS -Doptimize=OFF -Duse_context=ON -Dbuild_docs=OFF -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
INSTALL_DIR "${dist_dir}"
UPDATE_DISCONNECTED 1
)

ExternalProject_Get_Property(project_cn-cbor install_dir)
Expand Down
24 changes: 23 additions & 1 deletion include/ls_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <sys/errno.h>
#include <sys/time.h>

#include "ls_mem.h"

Expand Down Expand Up @@ -215,5 +216,26 @@ LS_API void ls_log_chunked(ls_loglevel level,
ls_log_generator_fn generator_fn, void *arg,
const char *fmt, ...) __attribute__ ((__format__ (__printf__, 4, 5)));

#define LS_LOG_ERR(err, what) ls_log(LS_LOG_ERROR, "%s:%d (%s) %d, %s", __FILE__, __LINE__, (what), (err).code, (err).message)
/**
* Log the specified time in human-readable form.
*
* @param[in] tv The time to log
* @param[in] tag A string describing the logged time
*/
LS_API void ls_log_format_timeval(struct timeval *tv, const char *tag);

/**
* Log the specified error, with the current information, where the error came
* from, etc.
*
* @param[in] err The error to log
* @param[in] what A string describing what failed
*/
#define LS_LOG_ERR(err, what) ls_log(LS_LOG_ERROR, "%s:%d->%s%zu (%s) %d, %s", __FILE__, __LINE__, (err).file, (err).line, (what), (err).code, (err).message)

/**
* ls_log equivalent of perror
*
* @param[in] what A string describing what failed
*/
#define LS_LOG_PERROR(what) ls_log(LS_LOG_ERROR, "%s:%d (%s) %d, %s", __FILE__, __LINE__, (what), errno, strerror(errno))
12 changes: 0 additions & 12 deletions include/ls_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,13 @@ LS_API void ls_data_set_memory_funcs(ls_data_malloc_func malloc_func,
* data. The function documentation will explicitly state what should be
* released using ls_data_free.
*
* \see api-design for a detailed discussion of jwc memor philosophy and design
*
* \param[in] ptr The pointer to be freed. May be NULL.
*/
LS_API void ls_data_free(void *ptr);

/**
* Allocate 'size' bytes of memory and return a pointer of the allocated memory.
*
* \see api-design for a detailed discussion of jwc memory philosophy and design
*
* \param[in] size The number of bytes to allocate.
* \retval void* Pointer to the allocated memory
*/
Expand All @@ -132,8 +128,6 @@ LS_API void * ls_data_malloc(size_t size);
/**
* Changes the size of the memory block pointed to by 'ptr' to size 'size'.
*
* \see api-design for a detailed discussion of jwc memory philosophy and design
*
* \param[in] ptr The original block of memory allocated through ls_data_malloc.
* if ptr is NULL, this function is equivalent to ls_data_malloc.
* \param[in] size The number of bytes to reallocate.
Expand All @@ -146,8 +140,6 @@ LS_API void * ls_data_realloc(void *ptr, size_t size);
* memory each and returns a pointer to the allocated memory. The allocated
* memory is filled with bytes of value zero.
*
* \see api-design for a detailed discussion of jwc memory philosophy and design
*
* \param[in] nmemb The number of contiguous chunks to allocate.
* \param[in] size The number of bytes to allocate per chunk.
* \retval void* Pointer to the allocated memory
Expand All @@ -157,8 +149,6 @@ LS_API void * ls_data_calloc(size_t nmemb, size_t size);
/**
* Duplicate a string by allocating memory
*
* \see api-design for a detailed discussion of jwc memory philosophy and design
*
* This function can generate the same errors as ls_data_malloc()
*
* \param[in] src The null (\\0) terminated string to copy. May be NULL
Expand All @@ -170,8 +160,6 @@ LS_API char * ls_data_strdup(const char *src);
/**
* Duplicate a string by allocating memory
*
* \see api-design for a detailed discussion of jwc memory philosophy and design
*
* This function can generate the same errors as ls_data_malloc()
*
* \param[in] src The potentially null (\\0) terminated string to copy. May be
Expand Down
120 changes: 120 additions & 0 deletions include/ls_pktinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* \file
* \brief
* Local address information, either v4 or v6
*
* Copyright (c) 2015 SPUDlib authors. See LICENSE file.
*/

#pragma once

#ifdef __APPLE__
#define __APPLE_USE_RFC_3542
#endif

#ifdef __linux__
/* needed for netinet/in.h */
#define _GNU_SOURCE 1
#define __USE_GNU 1
#endif

#include <netinet/in.h>
#include "ls_basics.h"
#include "ls_error.h"

/**
* A structure that holds either a struct in_pktinfo or a struct in6_pktinfo
* as needed for an IPv4 or IPv6 inbound destination address.
*/
typedef struct _ls_pktinfo ls_pktinfo;

/**
* Create a pktinfo structure. Allocates data that must be freed with
* ls_pktinfo_destroy.
*
* @param[out] p Created pktinfo
* @param[out] err The error information (provide NULL to ignore)
* @return true on success
*/
LS_API bool ls_pktinfo_create(ls_pktinfo **p, ls_err *err);

/**
* Destroy a previously-created pktinfo.
*
* @param[in] p The pktinfo to free
*/
LS_API void ls_pktinfo_destroy(ls_pktinfo *p);

/**
* Clear the data stored in the pktinfo.
*
* @param[in] p The pktinfo to clear
*/
LS_API void ls_pktinfo_clear(ls_pktinfo *p);

/**
* Duplicate a pktinfo. Allocates data that must be freed with
* ls_pktinfo_destroy.
*
* @param[in] source The pktinfo to copy
* @param[out] dest The new copy
* @param[out] err The error information (provide NULL to ignore)
* @return True on success
*/
LS_API bool ls_pktinfo_dup(ls_pktinfo *source, ls_pktinfo **dest, ls_err *err);

/**
* Set the IPv4 in_pktinfo.
*
* @param[in] p The pktinfo to modify
* @param[in] info The actual information about a packet that was received
*/
LS_API void ls_pktinfo_set4(ls_pktinfo *p, struct in_pktinfo *info);

/**
* Set the IPv6 in_pktinfo.
*
* @param[in] p The pktinfo to modify
* @param[in] info The actual information about a packet that was received
*/
LS_API void ls_pktinfo_set6(ls_pktinfo *p, struct in6_pktinfo *info);

/**
* Fill in a socket address from the pktinfo. The port will be set to -1.
*
* @param[in] p The pktinfo to access
* @param[out] addr The address to fill in
* @param[inout] addr_len On input, the length of addr, in bytes.
* On output, the number of bytes used.
* @param[out] err The error information (provide NULL to ignore)
* @return True on success
*/
LS_API bool ls_pktinfo_get_addr(ls_pktinfo *p,
struct sockaddr *addr,
socklen_t *addr_len,
ls_err *err);

/**
* Has the pktinfo had info assigned to it?
*
* @param[in] p The pktinfo to access
* @return True if information has been set
*/
LS_API bool ls_pktinfo_is_full(ls_pktinfo *p);

/**
* Get the correct v4/v6 info back out.
* @param[in] p The pktinfo to access
* @return The info
*/
LS_API void *ls_pktinfo_get_info(ls_pktinfo *p);

/**
* Fill in a struct cmsg for an outbound packet, with the info received
* from an inbound packet.
*
* @param[in] p The pktinfo to access
* @param[out] cmsg The cmsg to fill in
* @return The number of bytes filled in to the cmsg, or a safe 0 on error.
*/
LS_API size_t ls_pktinfo_cmsg(ls_pktinfo *p, struct cmsghdr *cmsg);
25 changes: 17 additions & 8 deletions include/ls_sockaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,34 @@

LS_API size_t ls_sockaddr_get_length(const struct sockaddr *addr);

LS_API bool ls_sockaddr_get_remote_ip_addr(struct sockaddr_in6 *remoteAddr,
const char *fqdn,
LS_API int ls_sockaddr_get_port(const struct sockaddr *addr);
LS_API void ls_sockaddr_set_port(const struct sockaddr *addr, int port);

LS_API bool ls_sockaddr_get_remote_ip_addr(const char *fqdn,
const char *port,
struct sockaddr *remoteAddr,
size_t addr_len,
ls_err *err);

LS_API void ls_sockaddr_v6_any(struct sockaddr_in6 * sa, int port);

LS_API void ls_sockaddr_v4_any(struct sockaddr_in * sa, int port);

LS_API void ls_sockaddr_copy(const struct sockaddr *src, struct sockaddr *dest);

LS_API const char *ls_sockaddr_to_string(const struct sockaddr *sa,
char *dest,
size_t destlen,
bool addport);

LS_API bool ls_addr_parse(const char *src,
struct in6_addr *addr,
ls_err *err);
LS_API int ls_sockaddr_cmp(const struct sockaddr *sa,
const struct sockaddr *sb);

LS_API int ls_addr_cmp(const struct in6_addr *a, const struct in6_addr *b);
LS_API bool ls_sockaddr_parse(const char *src,
struct sockaddr *addr,
size_t addr_len,
ls_err *err);

LS_API int ls_sockaddr_cmp(const struct sockaddr * sa,
const struct sockaddr * sb);
// Intentionally "addr", not "sockaddr"
LS_API int ls_addr_cmp6(const struct in6_addr *a,
const struct in6_addr *b);

0 comments on commit a7b2938

Please sign in to comment.