diff --git a/Makefile b/Makefile index 52d0e3e..8d7759a 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ CFLAGS=-g -O2 LDFLAGS= CPPFLAGS= DEFS=-DHAVE_CONFIG_H -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb +COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -EXTRA_LIBS= -lreadline -lconfig -LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -lrt ${EXTRA_LIBS} +EXTRA_LIBS= -lreadline -lrt -lconfig +LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic ${EXTRA_LIBS} LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS} HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h diff --git a/Makefile.in b/Makefile.in index 89a0ab9..cf92f28 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,10 +4,10 @@ CFLAGS=@CFLAGS@ LDFLAGS=@LDFLAGS@ CPPFLAGS=@CPPFLAGS@ DEFS=@DEFS@ -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb +COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated -fno-strict-aliasing -fno-omit-frame-pointer -ggdb EXTRA_LIBS=@EXTRA_LIBS@ -LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -lrt ${EXTRA_LIBS} +LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic ${EXTRA_LIBS} LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS} HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h diff --git a/configure b/configure index 4bb34ea..49c45d3 100755 --- a/configure +++ b/configure @@ -3127,6 +3127,49 @@ $as_echo "#define READLINE_EDIT 1" >>confdefs.h fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5 +$as_echo_n "checking for clock_gettime in -lrt... " >&6; } +if ${ac_cv_lib_rt_clock_gettime+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrt $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char clock_gettime (); +int +main () +{ +return clock_gettime (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_rt_clock_gettime=yes +else + ac_cv_lib_rt_clock_gettime=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5 +$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; } +if test "x$ac_cv_lib_rt_clock_gettime" = xyes; then : + + EXTRA_LIBS+=" -lrt" ; + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking Checking for libconfig" >&5 $as_echo_n "checking Checking for libconfig... " >&6; } # Check whether --enable-libconfig was given. diff --git a/configure.ac b/configure.ac index f319a33..a1d2d47 100644 --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,14 @@ AC_CHECK_LIB([readline], [rl_save_prompt], ] ) +AC_CHECK_LIB([rt], [clock_gettime], + [ + [ EXTRA_LIBS+=" -lrt" ; ] + ], + [ + ] +) + AC_MSG_CHECKING([Checking for libconfig]) AC_ARG_ENABLE(libconfig,[--enable-libconfig/--disable-libconfig], [ diff --git a/interface.c b/interface.c index 28cc5dd..3d87912 100644 --- a/interface.c +++ b/interface.c @@ -30,8 +30,8 @@ #include #include #else -#include -#include +#include +#include #endif #include "include.h" @@ -48,6 +48,7 @@ int unread_messages; int msg_num_mode; int in_readline; +int readline_active; long long cur_uploading_bytes; long long cur_uploaded_bytes; @@ -236,7 +237,9 @@ void set_prompt (const char *s) { void update_prompt (void) { print_start (); set_prompt (get_default_prompt ()); - rl_redisplay (); + if (readline_active) { + rl_redisplay (); + } print_end (); } diff --git a/loop.c b/loop.c index 15821f1..4bb3515 100644 --- a/loop.c +++ b/loop.c @@ -28,8 +28,8 @@ #include #include #else -#include -#include +#include +#include #endif #include diff --git a/mtproto-client.c b/mtproto-client.c index 23b4063..c538e44 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -72,13 +72,8 @@ long long precise_time; long long precise_time_rdtsc; double get_utime (int clock_id) { struct timespec T; - #if _POSIX_TIMERS - assert (clock_gettime (clock_id, &T) >= 0); + my_clock_gettime (clock_id, &T); double res = T.tv_sec + (double) T.tv_nsec * 1e-9; - #else - #error "No high-precision clock" - double res = time (); - #endif if (clock_id == CLOCK_REALTIME) { precise_time = (long long) (res * (1LL << 32)); precise_time_rdtsc = rdtsc (); @@ -835,6 +830,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { { peer_id_t user_id = MK_USER (fetch_int ()); peer_t *UC = user_chat_get (user_id); + fetch_date (); if (UC) { struct user *U = &UC->user; @@ -852,6 +848,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { U->photo_small.dc = -2; } else { assert (y == CODE_user_profile_photo); + fetch_long (); // photo_id fetch_file_location (&U->photo_small); fetch_file_location (&U->photo_big); } @@ -865,6 +862,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { fetch_file_location (&t); } } + fetch_bool (); } break; case CODE_update_restore_messages: @@ -1412,25 +1410,35 @@ int rpc_execute (struct connection *c, int op, int len) { logprintf ( "have %d Response bytes\n", Response_len); } +#ifndef __MACH__ setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); +#endif int o = c_state; if (GET_DC(c)->flags & 1) { o = st_authorized;} switch (o) { case st_reqpq_sent: process_respq_answer (c, Response/* + 8*/, Response_len/* - 12*/); +#ifndef __MACH__ setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); +#endif return 0; case st_reqdh_sent: process_dh_answer (c, Response/* + 8*/, Response_len/* - 12*/); +#ifndef __MACH__ setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); +#endif return 0; case st_client_dh_sent: process_auth_complete (c, Response/* + 8*/, Response_len/* - 12*/); +#ifndef __MACH__ setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); +#endif return 0; case st_authorized: process_rpc_message (c, (void *)(Response/* + 8*/), Response_len/* - 12*/); +#ifndef __MACH__ setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); +#endif return 0; default: logprintf ( "fatal: cannot receive answer in state %d\n", c_state); @@ -1456,7 +1464,9 @@ int tc_becomes_ready (struct connection *c) { assert (write_out (c, &byte, 1) == 1); flush_out (c); +#ifndef __MACH__ setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); +#endif int o = c_state; if (GET_DC(c)->flags & 1) { o = st_authorized; } switch (o) { diff --git a/mtproto-common.c b/mtproto-common.c index 201ab68..ab3614e 100644 --- a/mtproto-common.c +++ b/mtproto-common.c @@ -36,6 +36,13 @@ #include "mtproto-common.h" #include "interface.h" +#include "include.h" + +#ifdef __MACH__ +#include +#include +#endif + int __packet_buffer[PACKET_BUFFER_SIZE], *packet_ptr; int *packet_buffer = __packet_buffer + 16; @@ -78,13 +85,28 @@ int get_random_bytes (void *buf, int n) { return r; } +void my_clock_gettime (int clock_id UU, struct timespec *T) { +#ifdef __MACH__ + // We are ignoring MONOTONIC and hope time doesn't go back to often + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + T->tv_sec = mts.tv_sec; + T->tv_nsec = mts.tv_nsec; +#else + assert (clock_gettime(clock_id, T) >= 0); +#endif +} + void prng_seed (const char *password_filename, int password_length) { unsigned char *a = calloc (64 + password_length, 1); assert (a != NULL); long long r = rdtsc (); struct timespec T; - assert (clock_gettime(CLOCK_REALTIME, &T) >= 0); + my_clock_gettime (CLOCK_REALTIME, &T); memcpy (a, &T.tv_sec, 4); memcpy (a+4, &T.tv_nsec, 4); memcpy (a+8, &r, 8); diff --git a/mtproto-common.h b/mtproto-common.h index 94c97ac..df696cc 100644 --- a/mtproto-common.h +++ b/mtproto-common.h @@ -385,4 +385,10 @@ static inline void hexdump_in (void) { static inline void hexdump_out (void) { hexdump (packet_buffer, packet_ptr); } + +#ifdef __MACH__ +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 +#endif +void my_clock_gettime (int clock_id, struct timespec *T); #endif diff --git a/net.c b/net.c index a17e3bb..4db2677 100644 --- a/net.c +++ b/net.c @@ -37,6 +37,10 @@ #include "tree.h" #include "interface.h" +#ifdef __MACH__ +#define POLLRDHUP 0 +#endif + DEFINE_TREE(int,int,int_cmp,0) int verbosity; diff --git a/queries.c b/queries.c index 74b01c9..61664b8 100644 --- a/queries.c +++ b/queries.c @@ -64,7 +64,7 @@ struct tree_query *queries_tree; double get_double_time (void) { struct timespec tv; - clock_gettime (CLOCK_REALTIME, &tv); + my_clock_gettime (CLOCK_REALTIME, &tv); return tv.tv_sec + 1e-9 * tv.tv_nsec; } diff --git a/tree.h b/tree.h index 8f38e17..d5cdb73 100644 --- a/tree.h +++ b/tree.h @@ -21,7 +21,9 @@ #include #include +#ifdef HAVE_MALLOC_H #include +#endif #include #define DEFINE_TREE(X_NAME, X_TYPE, X_CMP, X_UNSET) \