Skip to content
This repository was archived by the owner on Jul 14, 2019. It is now read-only.

Commit 2bf5790

Browse files
author
Lior Amram
committed
merge fixes/changes
1 parent 1da5287 commit 2bf5790

30 files changed

+378
-92
lines changed

examples/mydump/src/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
all:
22
@$(MAKE) -s -f mydump.mk
3+
ifneq ($(wildcard /usr/include/mysql/mysql.h),)
34
@$(MAKE) -s -f mydumper.mk
5+
endif
46

57
clean:
68
@$(MAKE) -s -f mydump.mk clean

include/ds_field.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static inline int TEMPLATE_FUNC(ds_field,T,init)(struct TEMPLATE(ds_field,T) *ds
3333
return LOGGER_PERROR_FUNC("fstat %s", filename), close(fd), -1;
3434
off_t size = st.st_size;
3535
if (size < (off_t)sizeof(int64_t))
36-
return LOGGER_ERROR_FUNC("%s, wrong file size: %zd", __FUNCTION__, size), close(fd), -1;
36+
return LOGGER_ERROR_FUNC("%s, wrong file size: %jd", __FUNCTION__, (intmax_t)size), close(fd), -1;
3737
if (0 != ((size - sizeof(int64_t)) % sizeof(T)))
3838
return LOGGER_ERROR_FUNC("%s: data is misaligned", filename), close(fd), -1;
3939
void *mem = (char *)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);

include/file_writer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct file_writer {
4545
};
4646

4747
_RIBS_INLINE_ void file_writer_make(struct file_writer *fw);
48+
_RIBS_INLINE_ int file_writer_attachfd(struct file_writer *fw, int fd, size_t initial_size);
4849
_RIBS_INLINE_ int file_writer_init(struct file_writer *fw, const char *filename);
4950
_RIBS_INLINE_ size_t file_writer_wavail(struct file_writer *fw);
5051
_RIBS_INLINE_ char *file_writer_wloc(struct file_writer *fw);

include/http_server.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ struct http_server {
6060
size_t init_payload_size;
6161
size_t max_req_size;
6262
size_t context_size;
63+
uint32_t bind_addr;
6364
};
6465

65-
#define HTTP_SERVER_INIT_DEFAULTS .stack_size = 0, .num_stacks = 0, .init_request_size = 8*1024, .init_header_size = 8*1024, .init_payload_size = 8*1024, .max_req_size = 0, .context_size = 0, .timeout_handler.timeout = 60000
66+
#define HTTP_SERVER_INIT_DEFAULTS .stack_size = 0, .num_stacks = 0, .init_request_size = 8*1024, .init_header_size = 8*1024, .init_payload_size = 8*1024, .max_req_size = 0, .context_size = 0, .timeout_handler.timeout = 60000, .bind_addr = INADDR_ANY
6667
#define HTTP_SERVER_INITIALIZER { HTTP_SERVER_INIT_DEFAULTS }
6768

6869
#define HTTP_SERVER_NOT_FOUND (-2)
6970

7071
int http_server_init(struct http_server *server);
72+
int http_server_init2(struct http_server *server);
7173
int http_server_init_acceptor(struct http_server *server);
7274
void http_server_header_start(const char *status, const char *content_type);
7375
void http_server_header_start_no_body(const char *status);
@@ -77,8 +79,13 @@ void http_server_set_session_cookie(const char *name, const char *value, const c
7779
struct vmbuf *http_server_begin_cookie(const char *name);
7880
struct vmbuf *http_server_end_cookie(time_t expires, const char *domain, const char *path);
7981
void http_server_response(const char *status, const char *content_type);
80-
void http_server_response_sprintf(const char *status, const char *content_type, const char *format, ...);
82+
void http_server_response_sprintf(const char *status, const char *content_type, const char *format, ...) __attribute__ ((format (gnu_printf, 3, 4)));
83+
void http_server_response_vsprintf(const char *status, const char *content_type, const char *format, va_list ap);
8184
void http_server_header_content_length(void);
85+
void http_server_header_redirect(const char *format, ...);
86+
void http_server_header_redirect2(const char *format, va_list ap);
87+
void http_server_redirect(const char *status, const char *content_type, const char *format, ...);
88+
void http_server_redirect2(const char *status, const char *content_type, const char *format, va_list ap);
8289
void http_server_fiber_main(void);
8390
int http_server_sendfile(const char *filename);
8491
int http_server_sendfile2(const char *filename, const char *additional_headers, const char *ext);

include/lhashtable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ struct lhashtable {
148148
int lhashtable_init(struct lhashtable *lht, const char *filename);
149149
int lhashtable_close(struct lhashtable *lht);
150150
uint64_t lhashtable_put(struct lhashtable *lht, const void *key, size_t key_len, const void *val, size_t val_len);
151+
uint64_t lhashtable_put_key(struct lhashtable *lht, const void *key, size_t key_len, size_t val_len, int *is_inserted);
151152
uint64_t lhashtable_get(struct lhashtable *lht, const void *key, size_t key_len);
152153
int lhashtable_del(struct lhashtable *lht, const void *key, size_t key_len);
153154
int lhashtable_foreach(struct lhashtable *lht, int (*callback)(uint64_t, void *), void *arg);

include/list.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct list {
2727
};
2828

2929
#define LIST_INITIALIZER(name) { &(name), &(name) }
30+
#define LIST_NULL_INITIALIZER { NULL, NULL }
3031
#define LIST_CREATE(name) struct list name = LIST_INITIALIZER(name);
3132

3233
#define LIST_ENTRY(ptr, type, member) \
@@ -37,6 +38,11 @@ _RIBS_INLINE_ void list_init(struct list *list) {
3738
list->prev = list;
3839
}
3940

41+
_RIBS_INLINE_ void list_clear(struct list *list) {
42+
list->next = NULL;
43+
list->prev = NULL;
44+
}
45+
4046
_RIBS_INLINE_ void list_insert_head(struct list *list, struct list *entry) {
4147
entry->next = list->next;
4248
entry->prev = list;

include/logger.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
#include "ribs_defs.h"
2424
#include <stdarg.h>
2525

26-
void logger_log(const char *format, ...);
27-
void logger_log_at(const char *filename, unsigned int linenum, const char *format, ...);
28-
void logger_error(const char *format, ...);
29-
void logger_error_at(const char *filename, unsigned int linenum, const char *format, ...);
30-
void logger_error_func_at(const char *filename, unsigned int linenum, const char *funcname, const char *format, ...);
31-
void logger_perror(const char *format, ...);
32-
void logger_perror_at(const char *filename, unsigned int linenum, const char *format, ...);
33-
void logger_perror_func_at(const char *filename, unsigned int linenum, const char *funcname, const char *format, ...);
26+
void logger_log(const char *format, ...) __attribute__ ((format (gnu_printf, 1, 2)));
27+
void logger_log_at(const char *filename, unsigned int linenum, const char *format, ...) __attribute__ ((format (gnu_printf, 3, 4)));
28+
void logger_error(const char *format, ...) __attribute__ ((format (gnu_printf, 1, 2)));
29+
void logger_error_at(const char *filename, unsigned int linenum, const char *format, ...) __attribute__ ((format (gnu_printf, 3, 4)));
30+
void logger_error_func_at(const char *filename, unsigned int linenum, const char *funcname, const char *format, ...) __attribute__ ((format (gnu_printf, 4, 5)));
31+
void logger_perror(const char *format, ...) __attribute__ ((format (gnu_printf, 1, 2)));
32+
void logger_perror_at(const char *filename, unsigned int linenum, const char *format, ...) __attribute__ ((format (gnu_printf, 3, 4)));
33+
void logger_perror_func_at(const char *filename, unsigned int linenum, const char *funcname, const char *format, ...) __attribute__ ((format (gnu_printf, 4, 5)));
3434
void logger_vlog(int fd, const char *format, const char *msg_class, va_list ap);
3535
void logger_vlog_at(int fd, const char *filename, unsigned int linenum, const char *format, const char *msg_class, va_list ap);
3636
void logger_vlog_func_at(int fd, const char *filename, unsigned int linenum, const char *funcname, const char *format, const char *msg_class, va_list ap);

include/mysql_helper.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ struct mysql_helper_column_map {
7171
};
7272

7373
#define MYSQL_HELPER_COL_MAP_GET_STR(d,m) (*((char **)((d) + (m)->data.ofs)))
74+
75+
/* field declaration helper macros */
76+
#define _MYSQL_HELPER_COL_MAP(type,name,is_un,mysqlt,field) \
77+
{#name,{mysql_helper_field_type_##field,is_un,mysqlt,sizeof(((struct mysql_helper_column_map *)0)->data.field[0])},{.field=&((type *)0)->name}}
78+
7479
#define MYSQL_HELPER_COL_MAP_I8(type,name) _MYSQL_HELPER_COL_MAP(type, name, 0, MYSQL_TYPE_TINY, i8)
7580
#define MYSQL_HELPER_COL_MAP_U8(type,name) _MYSQL_HELPER_COL_MAP(type, name, 1, MYSQL_TYPE_TINY, u8)
7681
#define MYSQL_HELPER_COL_MAP_I16(type,name) _MYSQL_HELPER_COL_MAP(type, name, 0, MYSQL_TYPE_SHORT, i16)
@@ -87,20 +92,16 @@ struct mysql_helper_column_map {
8792
#define MYSQL_HELPER_COL_MAP_CUSTOM_STR(name,value) \
8893
{name,{mysql_helper_field_type_cstr,0,MYSQL_TYPE_STRING,0},{.custom_str=value}}
8994

90-
#define MYSQL_HELPER_COL_MAP_ADD_IF(name, class, type, buf) \
91-
do { \
92-
if (*name) { \
93-
struct mysql_helper_column_map __field__ = MYSQL_HELPER_COL_MAP_##type(class, name); \
94-
vmbuf_memcpy(&buf, &__field__, sizeof(__field__)); \
95-
} \
96-
} while (0)
97-
9895
#define MYSQL_HELPER_COL_MAP_ADD(name, class, type, buf) \
9996
{ \
100-
struct mysql_helper_column_map __field__ = MYSQL_HELPER_COL_MAP_##type(class, name); \
97+
struct mysql_helper_column_map __field__ = \
98+
MYSQL_HELPER_COL_MAP_##type(class, name); \
10199
vmbuf_memcpy(&buf, &__field__, sizeof(__field__)); \
102100
}
103101

102+
#define MYSQL_HELPER_COL_MAP_ADD_IF(name, class, type, buf) \
103+
if (name && *name) \
104+
MYSQL_HELPER_COL_MAP_ADD(name, class, type, buf)
104105

105106
void mysql_helper_connect_init(struct mysql_helper *mysql_helper);
106107
int mysql_helper_real_connect(struct mysql_helper *mysql_helper, struct mysql_login_info *login_info);
@@ -150,10 +151,6 @@ enum {
150151
mysql_helper_field_type_ts_unix
151152
};
152153

153-
/* field declaration helper macros */
154-
#define _MYSQL_HELPER_COL_MAP(type,name,is_un,mysqlt,field) \
155-
{#name,{mysql_helper_field_type_##field,is_un,mysqlt,sizeof(((struct mysql_helper_column_map *)0)->data.field[0])},{.field=&((type *)0)->name}}
156-
157154
/* get data from field */
158155
#define _MYSQL_HELPER_FIELD_TYPE_TO_STR(T) case mysql_helper_field_type_##T: return #T
159156

include/ribs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "context.h"
2727
#include "ctx_pool.h"
2828
#include "hashtable.h"
29+
#include "thashtable.h"
2930
#include "lhashtable.h"
3031
#include "epoll_worker.h"
3132
#include "logger.h"

include/ribs_defs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@
4343

4444
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
4545

46+
#define ribs_min(a,b) \
47+
({ __typeof__ (a) _a = (a); \
48+
__typeof__ (b) _b = (b); \
49+
_a < _b ? _a : _b; })
50+
51+
#define ribs_max(a,b) \
52+
({ __typeof__ (a) _a = (a); \
53+
__typeof__ (b) _b = (b); \
54+
_a > _b ? _a : _b; })
55+
4656
#endif // _RIBS_DEFS__H_

0 commit comments

Comments
 (0)