Commit 65edc178 authored by vysheng's avatar vysheng

Maybe it would compile on mac now

parent faaf589e
...@@ -4,10 +4,10 @@ CFLAGS=-g -O2 ...@@ -4,10 +4,10 @@ CFLAGS=-g -O2
LDFLAGS= LDFLAGS=
CPPFLAGS= CPPFLAGS=
DEFS=-DHAVE_CONFIG_H 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 EXTRA_LIBS= -lreadline -lrt -lconfig
LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -lrt ${EXTRA_LIBS} LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic ${EXTRA_LIBS}
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS} 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 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
......
...@@ -4,10 +4,10 @@ CFLAGS=@CFLAGS@ ...@@ -4,10 +4,10 @@ CFLAGS=@CFLAGS@
LDFLAGS=@LDFLAGS@ LDFLAGS=@LDFLAGS@
CPPFLAGS=@CPPFLAGS@ CPPFLAGS=@CPPFLAGS@
DEFS=@DEFS@ 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@ 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} 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 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
......
...@@ -3127,6 +3127,49 @@ $as_echo "#define READLINE_EDIT 1" >>confdefs.h ...@@ -3127,6 +3127,49 @@ $as_echo "#define READLINE_EDIT 1" >>confdefs.h
fi 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 "$as_me:${as_lineno-$LINENO}: checking Checking for libconfig" >&5
$as_echo_n "checking Checking for libconfig... " >&6; } $as_echo_n "checking Checking for libconfig... " >&6; }
# Check whether --enable-libconfig was given. # Check whether --enable-libconfig was given.
......
...@@ -24,6 +24,14 @@ AC_CHECK_LIB([readline], [rl_save_prompt], ...@@ -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_MSG_CHECKING([Checking for libconfig])
AC_ARG_ENABLE(libconfig,[--enable-libconfig/--disable-libconfig], AC_ARG_ENABLE(libconfig,[--enable-libconfig/--disable-libconfig],
[ [
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
#else #else
#include <editline/readline.h> #include <readline/readline.h>
#include <editline/history.h> #include <readline/history.h>
#endif #endif
#include "include.h" #include "include.h"
...@@ -48,6 +48,7 @@ int unread_messages; ...@@ -48,6 +48,7 @@ int unread_messages;
int msg_num_mode; int msg_num_mode;
int in_readline; int in_readline;
int readline_active;
long long cur_uploading_bytes; long long cur_uploading_bytes;
long long cur_uploaded_bytes; long long cur_uploaded_bytes;
...@@ -236,7 +237,9 @@ void set_prompt (const char *s) { ...@@ -236,7 +237,9 @@ void set_prompt (const char *s) {
void update_prompt (void) { void update_prompt (void) {
print_start (); print_start ();
set_prompt (get_default_prompt ()); set_prompt (get_default_prompt ());
rl_redisplay (); if (readline_active) {
rl_redisplay ();
}
print_end (); print_end ();
} }
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
#else #else
#include <editline/readline.h> #include <readline/readline.h>
#include <editline/history.h> #include <readline/history.h>
#endif #endif
#include <errno.h> #include <errno.h>
......
...@@ -72,13 +72,8 @@ long long precise_time; ...@@ -72,13 +72,8 @@ long long precise_time;
long long precise_time_rdtsc; long long precise_time_rdtsc;
double get_utime (int clock_id) { double get_utime (int clock_id) {
struct timespec T; struct timespec T;
#if _POSIX_TIMERS my_clock_gettime (clock_id, &T);
assert (clock_gettime (clock_id, &T) >= 0);
double res = T.tv_sec + (double) T.tv_nsec * 1e-9; 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) { if (clock_id == CLOCK_REALTIME) {
precise_time = (long long) (res * (1LL << 32)); precise_time = (long long) (res * (1LL << 32));
precise_time_rdtsc = rdtsc (); precise_time_rdtsc = rdtsc ();
...@@ -835,6 +830,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { ...@@ -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_id_t user_id = MK_USER (fetch_int ());
peer_t *UC = user_chat_get (user_id); peer_t *UC = user_chat_get (user_id);
fetch_date ();
if (UC) { if (UC) {
struct user *U = &UC->user; struct user *U = &UC->user;
...@@ -852,6 +848,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { ...@@ -852,6 +848,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
U->photo_small.dc = -2; U->photo_small.dc = -2;
} else { } else {
assert (y == CODE_user_profile_photo); assert (y == CODE_user_profile_photo);
fetch_long (); // photo_id
fetch_file_location (&U->photo_small); fetch_file_location (&U->photo_small);
fetch_file_location (&U->photo_big); fetch_file_location (&U->photo_big);
} }
...@@ -865,6 +862,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { ...@@ -865,6 +862,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
fetch_file_location (&t); fetch_file_location (&t);
} }
} }
fetch_bool ();
} }
break; break;
case CODE_update_restore_messages: case CODE_update_restore_messages:
...@@ -1412,25 +1410,35 @@ int rpc_execute (struct connection *c, int op, int len) { ...@@ -1412,25 +1410,35 @@ int rpc_execute (struct connection *c, int op, int len) {
logprintf ( "have %d Response bytes\n", Response_len); logprintf ( "have %d Response bytes\n", Response_len);
} }
#ifndef __MACH__
setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4);
#endif
int o = c_state; int o = c_state;
if (GET_DC(c)->flags & 1) { o = st_authorized;} if (GET_DC(c)->flags & 1) { o = st_authorized;}
switch (o) { switch (o) {
case st_reqpq_sent: case st_reqpq_sent:
process_respq_answer (c, Response/* + 8*/, Response_len/* - 12*/); process_respq_answer (c, Response/* + 8*/, Response_len/* - 12*/);
#ifndef __MACH__
setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4);
#endif
return 0; return 0;
case st_reqdh_sent: case st_reqdh_sent:
process_dh_answer (c, Response/* + 8*/, Response_len/* - 12*/); process_dh_answer (c, Response/* + 8*/, Response_len/* - 12*/);
#ifndef __MACH__
setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4);
#endif
return 0; return 0;
case st_client_dh_sent: case st_client_dh_sent:
process_auth_complete (c, Response/* + 8*/, Response_len/* - 12*/); process_auth_complete (c, Response/* + 8*/, Response_len/* - 12*/);
#ifndef __MACH__
setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4);
#endif
return 0; return 0;
case st_authorized: case st_authorized:
process_rpc_message (c, (void *)(Response/* + 8*/), Response_len/* - 12*/); process_rpc_message (c, (void *)(Response/* + 8*/), Response_len/* - 12*/);
#ifndef __MACH__
setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4);
#endif
return 0; return 0;
default: default:
logprintf ( "fatal: cannot receive answer in state %d\n", c_state); logprintf ( "fatal: cannot receive answer in state %d\n", c_state);
...@@ -1456,7 +1464,9 @@ int tc_becomes_ready (struct connection *c) { ...@@ -1456,7 +1464,9 @@ int tc_becomes_ready (struct connection *c) {
assert (write_out (c, &byte, 1) == 1); assert (write_out (c, &byte, 1) == 1);
flush_out (c); flush_out (c);
#ifndef __MACH__
setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4);
#endif
int o = c_state; int o = c_state;
if (GET_DC(c)->flags & 1) { o = st_authorized; } if (GET_DC(c)->flags & 1) { o = st_authorized; }
switch (o) { switch (o) {
......
...@@ -36,6 +36,13 @@ ...@@ -36,6 +36,13 @@
#include "mtproto-common.h" #include "mtproto-common.h"
#include "interface.h" #include "interface.h"
#include "include.h"
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
int __packet_buffer[PACKET_BUFFER_SIZE], *packet_ptr; int __packet_buffer[PACKET_BUFFER_SIZE], *packet_ptr;
int *packet_buffer = __packet_buffer + 16; int *packet_buffer = __packet_buffer + 16;
...@@ -78,13 +85,28 @@ int get_random_bytes (void *buf, int n) { ...@@ -78,13 +85,28 @@ int get_random_bytes (void *buf, int n) {
return r; 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) { void prng_seed (const char *password_filename, int password_length) {
unsigned char *a = calloc (64 + password_length, 1); unsigned char *a = calloc (64 + password_length, 1);
assert (a != NULL); assert (a != NULL);
long long r = rdtsc (); long long r = rdtsc ();
struct timespec T; struct timespec T;
assert (clock_gettime(CLOCK_REALTIME, &T) >= 0); my_clock_gettime (CLOCK_REALTIME, &T);
memcpy (a, &T.tv_sec, 4); memcpy (a, &T.tv_sec, 4);
memcpy (a+4, &T.tv_nsec, 4); memcpy (a+4, &T.tv_nsec, 4);
memcpy (a+8, &r, 8); memcpy (a+8, &r, 8);
......
...@@ -385,4 +385,10 @@ static inline void hexdump_in (void) { ...@@ -385,4 +385,10 @@ static inline void hexdump_in (void) {
static inline void hexdump_out (void) { static inline void hexdump_out (void) {
hexdump (packet_buffer, packet_ptr); 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 #endif
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
#include "tree.h" #include "tree.h"
#include "interface.h" #include "interface.h"
#ifdef __MACH__
#define POLLRDHUP 0
#endif
DEFINE_TREE(int,int,int_cmp,0) DEFINE_TREE(int,int,int_cmp,0)
int verbosity; int verbosity;
......
...@@ -64,7 +64,7 @@ struct tree_query *queries_tree; ...@@ -64,7 +64,7 @@ struct tree_query *queries_tree;
double get_double_time (void) { double get_double_time (void) {
struct timespec tv; struct timespec tv;
clock_gettime (CLOCK_REALTIME, &tv); my_clock_gettime (CLOCK_REALTIME, &tv);
return tv.tv_sec + 1e-9 * tv.tv_nsec; return tv.tv_sec + 1e-9 * tv.tv_nsec;
} }
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#include <stdio.h> #include <stdio.h>
#include <memory.h> #include <memory.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h> #include <malloc.h>
#endif
#include <assert.h> #include <assert.h>
#define DEFINE_TREE(X_NAME, X_TYPE, X_CMP, X_UNSET) \ #define DEFINE_TREE(X_NAME, X_TYPE, X_CMP, X_UNSET) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment