* Removed ntime dependency from fserv.c.
-Isdk/include/amtrucks/ \
-Isdk/include/eurotrucks2
-CFLAGS=-Wall -Wextra -std=gnu99 -DDEBUG -I.
+CFLAGS=-Wall -Wextra -std=c99 -DDEBUG -I.
UNAME:= $(shell uname -s)
telemetry.so: telemetry.cpp $(SDK_HEADERS)
g++ -o $@ -fPIC -Wall --shared -Wl,$(LIB_NAME_OPTION),$@ $(SDK_INCLUDES) telemetry.cpp
-telehttpd: telehttpd.o shmget.o net.o fserv.o ntime.o
+telehttpd: telehttpd.o shmget.o net.o fserv.o
$(CC) $(LDFLAGS) -o $@ -pthread $^
telelogger: telelogger.o shmget.o
#include "fserv.h"
#include "log.h"
-#include "ntime.h"
#define BUFSIZE 65536
return 0;
}
-#ifdef DEBUG
-// returns NOW which can be fed as start in subsequent calls
-static unsigned long fserv_report_speed( size_t sent, unsigned long start )
-{
- unsigned long now = ntime_to_ms( nclock_get() );
- unsigned long tsdiff = now - start;
- if ( tsdiff >= 3 )
- {
- DPRINT( "%lu bytes in %lu ms @ %5.2f kB/s\n",
- sent, tsdiff, (double)sent * 1000 / tsdiff / 1024 );
- }
- return now;
-}
-#endif
-
int fserv_sendfile( int outfd, struct file_info_t *fi )
{
off_t sent = 0;
int err = -1;
char buf[BUFSIZE];
size_t bread, bwr;
-#ifdef DEBUG
- size_t str = 0;
- unsigned long start, chkt;
- start = chkt = ntime_to_ms( nclock_get() );
-#endif
DPRINT( "send file contents\n" );
if ( fi->coff != lseek( fi->fd, fi->coff, SEEK_SET ) )
goto DONE;
}
sent += bwr;
-#ifdef DEBUG
- str += bwr;
- if ( ntime_to_ms( nclock_get() ) - chkt >= 10000 )
- {
- chkt = fserv_report_speed( str, chkt );
- str = 0;
- }
-#endif
}
err = 0;
DONE:
fi->remn -= sent;
DPRINT( "Sent %lu, remaining %lu, resume at %lu\n",
sent, fi->remn, fi->coff );
-#ifdef DEBUG
- if ( sent > 0 )
- fserv_report_speed( sent, start );
-#endif
return err;
}
* 2013-05-31 support bind address, statics no more [uw]
*/
+// Needed for inet_aton() and herror():
+#define _DEFAULT_SOURCE
+
#include <stdio.h>
#include <string.h>
+++ /dev/null
-/*
-
- ntime.c
-
- Get and convert absolute and relative times expressed in nanoseconds
- represented as simple integral objects. Accuracy depends on the
- underlying implementation and hardware.
-
- The getter functions are basically convenience wrappers for the
- POSIX clock_gettime() and clock_getres() interface, which must be
-available on the target system. (Link with librt, if required.)
-
-
- Copyright (c) 2013 Urban Wallasch
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
-*/
-
-
-#include <ntime.h>
-
-
-#if defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
-#include <unistd.h>
-#endif
-
-#if !defined(_POSIX_TIMERS) || !(_POSIX_TIMERS > 0) || !defined(CLOCK_REALTIME)
-#error "POSIX timers required but not available!"
-#endif
-
-/*
- Select the monotonic clock source best suited for relative timing
- measurements.
-
- Note 1:
- CLOCK_MONOTONIC_RAW provided by modern Linux based systems seems a
- better choice over CLOCK_MONOTONIC, since it is guaranteed to not
- be influenced by NTP slew, thus running at a constant speed. The
- drawback is it might run slightly slower or faster than the adjusted
- monotonic clock.
-
- Note 2:
- Untested on AIX, BSD, Solaris.
-*/
-#if defined(CLOCK_MONOTONIC_PRECISE) /* BSD */
-#define NT_MONOCLOCK CLOCK_MONOTONIC_PRECISE
-#elif defined(CLOCK_MONOTONIC_RAW) /* Linux */
-#define NT_MONOCLOCK CLOCK_MONOTONIC_RAW
-#elif defined(CLOCK_HIGHRES) /* Solaris */
-#define NT_MONOCLOCK CLOCK_HIGHRES
-#elif defined(CLOCK_MONOTONIC) /* AIX, BSD, Linux, Solaris, generally POSIX compliant*/
-#define NT_MONOCLOCK CLOCK_MONOTONIC
-#else
-#error "No monotonic clock available!"
-#endif
-
-#define NT_REALCLOCK CLOCK_REALTIME
-
-
-struct timeval *ntime_to_timeval( ntime_t t, struct timeval *tv )
-{
- tv->tv_sec = t / NT_NS_PER_S;
- tv->tv_usec = t % NT_NS_PER_S / NT_NS_PER_US;
- return tv;
-}
-
-ntime_t ntime_from_timeval( struct timeval *tv )
-{
- return (ntime_t)tv->tv_sec * NT_NS_PER_S + tv->tv_usec * NT_NS_PER_US;
-}
-
-
-struct timespec *ntime_to_timespec( ntime_t t, struct timespec *ts )
-{
- ts->tv_sec = t / NT_NS_PER_S;
- ts->tv_nsec = t % NT_NS_PER_S;
- return ts;
-}
-
-ntime_t ntime_from_timespec( struct timespec *ts )
-{
- return (ntime_t)ts->tv_sec * NT_NS_PER_S + ts->tv_nsec;
-}
-
-
-ntime_t ntime_get( void )
-{
- struct timespec ts;
- if ( 0 != clock_gettime( NT_REALCLOCK, &ts ) )
- return -1;
- return ntime_from_timespec( &ts );
-}\r
-
-ntime_t ntime_res( void )
-{
- struct timespec ts;
- if ( 0 != clock_getres( NT_REALCLOCK, &ts ) )
- return -1;
- return ntime_from_timespec( &ts );
-}\r
-
-
-ntime_t nclock_get( void )
-{
- struct timespec ts;
- if ( 0 != clock_gettime( NT_MONOCLOCK, &ts ) )
- return -1;
- return ntime_from_timespec( &ts );
-}\r
-
-ntime_t nclock_res( void )
-{
- struct timespec ts;
- if ( 0 != clock_getres( NT_MONOCLOCK, &ts ) )
- return -1;
- return ntime_from_timespec( &ts );
-}\r
-
-/* EOF */
+++ /dev/null
-/*
-
- ntime.h
-
- Get and convert absolute and relative times expressed in nanoseconds
- represented as simple integral objects. Accuracy depends on the
- underlying implementation and hardware.
-
- The getter functions are basically convenience wrappers for the
- POSIX clock_gettime() and clock_getres() interface, which must be
- available on the target system. (Link with librt, if required.)
-
-
- Copyright (c) 2013 Urban Wallasch
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
-*/
-
-#ifndef NTIME_H_INCLUDED
-#define NTIME_H_INCLUDED
-
-#ifdef _cplusplus
-extern "C" {
-#endif
-
-#include <inttypes.h>
-#include <time.h>
-#include <sys/time.h>
-
-
-/*
- Conversion specifier string macros suitable for use in fprintf/fscanf
- format strings.
-*/
-#define PRI_ntime PRIdLEAST64
-#define SCA_ntime SCAdLEAST64
-
-/*
- Guess what. Got tired of typing zeroes.
-*/
-#define NT_NS_PER_S (1000*1000*1000)
-#define NT_NS_PER_MS (1000*1000)
-#define NT_NS_PER_US (1000)
-
-#define NT_US_PER_S (1000*1000)
-#define NT_US_PER_MS (1000)
-
-#define NT_MS_PER_S (1000)
-
-/*
- Type to hold ntime values. Capable of holding absolute time
- values in nanosecond resolution at least up until the year 2262.
-*/
-typedef int_least64_t ntime_t;
-
-
-/*
- Convert between ntime_t and other common time representations.
- No rounding applied so that results should agree with those
- returned by time() and gettimeofday(). Conversions to and from
- structural types are implemented as functions to steer clear
- of macros evaluating their arguments more than once.
-
- The (in principle good) idea to use inline functions here was
- dropped due to the incomprehensible mess of 'inline' semantics
- across various C standards and compilers. Instead, use a high
- optimization setting and let the comopiler figure out the best
- way to deal with it. Sigh. [uw 2014-03-21]
-*/
-
-#define ntime_to_time_t(t) ( (time_t)( (t) / NT_NS_PER_S ) )
-#define ntime_from_time_t(t) ( (ntime_t)(t) * NT_NS_PER_S )
-
-#define ntime_to_ms(t) ( (t) / NT_NS_PER_MS )
-#define ntime_from_ms(m) ( (ntime_t)(m) * NT_NS_PER_MS )
-
-extern struct timeval *ntime_to_timeval( ntime_t t, struct timeval *tv );
-extern ntime_t ntime_from_timeval( struct timeval *tv );
-
-extern struct timespec *ntime_to_timespec( ntime_t t, struct timespec *ts );
-extern ntime_t ntime_from_timespec( struct timespec *ts );
-
-
-/*
- Get real ("wall-clock") time in nanoseconds since UNIX epoch.
- This may experience discontinuous jumps due to time adjustments.
- Use this in (absolute) calendar time calculations.
- Returns -1 on error.
-*/
-extern ntime_t ntime_get( void );
-
-/*
- Get real ("wall-")clock resolution in nanoseconds.
- Returns -1 on error.
-*/
-extern ntime_t ntime_res( void );
-
-/*
- Get monotonic clock time in nanoseconds since arbitrary epoch,
- usually boot time on Linux systems; guaranteed to not "jump"
- due to time adjustments, but might be subject to NTP slew,
- depending on the target system. Best suited for (relative) timing
- purposes.
- Returns -1 on error.
-*/
-extern ntime_t nclock_get( void );
-
-/*
- Get monotonic clock resolution in nanoseconds.
- Returns -1 on error.
-*/
-extern ntime_t nclock_res( void );
-
-
-#ifdef _cplusplus
-} //extern "C" {
-#endif
-
-#endif //ndef NTIME_H_INCLUDED
-
-/* EOF */
+// Needed for ipc.h:
+#define _XOPEN_SOURCE
+
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+// Needed for getopt():
+#define _XOPEN_SOURCE
+
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>