Skip to content

Commit 3f13c27

Browse files
committed
WIP on sockhub integration. Now it compiles.
1 parent 603a97a commit 3f13c27

File tree

6 files changed

+327
-241
lines changed

6 files changed

+327
-241
lines changed

contrib/pg_dtm/dtmd/Makefile

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CC=gcc
22
CFLAGS=-g -O2 -Wall -Iinclude -D_LARGEFILE64_SOURCE # -DDEBUG
3-
LIBUV_PREFIX=$(HOME)/libuv-build
4-
LIBUV_CFLAGS=-I"$(LIBUV_PREFIX)/include" -L"$(LIBUV_PREFIX)/lib"
5-
LIBUV_LDFLAGS=-luv -pthread -lrt
3+
SOCKHUB_PREFIX=../sockhub
4+
SOCKHUB_CFLAGS=-I"$(SOCKHUB_PREFIX)"
5+
SOCKHUB_LDFLAGS=-lsockhub -L"$(SOCKHUB_PREFIX)"
66

77
SYSTEM=$(shell uname -s)
88
ifeq ($(SYSTEM),Darwin)
@@ -15,18 +15,18 @@ all: bin/dtmd
1515
@echo Done.
1616
@echo Feel free to run the tests with \'make check\'.
1717

18-
bin/dtmd: obj/eventwrap.o obj/main.o obj/parser.o obj/clog.o obj/clogfile.o obj/util.o obj/transaction.o obj/snapshot.o | bindir objdir
19-
$(CC) -o bin/dtmd $(CFLAGS) $(LIBUV_CFLAGS) \
20-
obj/eventwrap.o obj/main.o obj/parser.o \
18+
bin/dtmd: obj/server.o obj/main.o obj/clog.o obj/clogfile.o obj/util.o obj/transaction.o obj/snapshot.o | bindir objdir
19+
$(CC) -o bin/dtmd $(CFLAGS) \
20+
obj/server.o obj/main.o \
2121
obj/clog.o obj/clogfile.o obj/util.o obj/transaction.o \
2222
obj/snapshot.o \
23-
$(LIBUV_LDFLAGS)
23+
$(SOCKHUB_LDFLAGS)
2424

25-
obj/eventwrap.o: src/eventwrap.c | objdir
26-
$(CC) -c -o obj/eventwrap.o $(CFLAGS) $(LIBUV_CFLAGS) src/eventwrap.c
25+
obj/server.o: src/server.c | objdir
26+
$(CC) -c -o obj/server.o $(CFLAGS) $(SOCKHUB_CFLAGS) src/server.c
2727

28-
check: bin/util-test bin/clog-test bin/parser-test
29-
./check.sh util parser clog
28+
check: bin/util-test bin/clog-test
29+
./check.sh util clog
3030

3131
obj/%.o: src/%.c | objdir
3232
$(CC) $(CFLAGS) -c -o $@ $<
@@ -37,9 +37,6 @@ bin/util-test: obj/util-test.o obj/util.o | bindir
3737
bin/clog-test: obj/clog-test.o obj/clog.o obj/clogfile.o obj/util.o | bindir
3838
$(CC) -o bin/clog-test $(CFLAGS) obj/clog-test.o obj/clog.o obj/clogfile.o obj/util.o
3939

40-
bin/parser-test: obj/parser-test.o obj/parser.o | bindir
41-
$(CC) -o bin/parser-test $(CFLAGS) obj/parser-test.o obj/parser.o
42-
4340
bindir:
4441
mkdir -p bin
4542

contrib/pg_dtm/dtmd/include/proto.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef PROTO_H
2+
#define PROTO_H
3+
4+
#define CMD_RESERVE 'r'
5+
#define CMD_BEGIN 'b'
6+
#define CMD_FOR 'y'
7+
#define CMD_AGAINST 'n'
8+
#define CMD_SNAPSHOT 'h'
9+
#define CMD_STATUS 's'
10+
11+
#define RES_FAILED 0xDEADBEEF
12+
#define RES_OK 0xC0FFEE
13+
#define RES_TRANSACTION_COMMITTED 1
14+
#define RES_TRANSACTION_ABORTED 2
15+
#define RES_TRANSACTION_INPROGRESS 3
16+
#define RES_TRANSACTION_UNKNOWN 4
17+
18+
#endif

contrib/pg_dtm/dtmd/include/server.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef SERVER_H
22
#define SERVER_H
33

4+
#include <stdbool.h>
5+
46
/*
57
* You should not want to know what is inside those structures.
68
*/
@@ -34,7 +36,7 @@ server_t server_init(
3436
int port,
3537
onmessage_callback_t onmessage,
3638
onconnect_callback_t onconnect,
37-
ondisconnect_callback_t ondisconnect,
39+
ondisconnect_callback_t ondisconnect
3840
);
3941

4042
/*
@@ -53,17 +55,17 @@ void server_loop(server_t server);
5355
* 'client'. The server does not care about this data and will not free it on
5456
* client disconnection.
5557
*/
56-
void client_set_data(client_t client, void *userdata);
57-
void *client_get_data(client_t client);
58+
void client_set_userdata(client_t client, void *userdata);
59+
void *client_get_userdata(client_t client);
5860

5961
/*
6062
* Puts an empty message header into the output buffer of the corresponding
6163
* socket. The message will not be sent until you call the _finish() method.
6264
* A call to this function may lead to a send() call if there is not enough
6365
* space in the buffer.
64-
*
66+
*
6567
* Returns 'true' on success, 'false' otherwise.
66-
*
68+
*
6769
* NOTE: Be careful not to call the _message_ methods for other clients until
6870
* you _finish() this message. This limitation is due to the fact that multiple
6971
* clients share the same socket.
@@ -74,17 +76,25 @@ bool client_message_start(client_t client);
7476
* Appends 'len' bytes of 'data' to the buffer of the corresponding socket.
7577
* A call to this function may lead to a send() call if there is not enough
7678
* space in the buffer.
77-
*
79+
*
7880
* Returns 'true' on success, 'false' otherwise.
7981
*/
8082
bool client_message_append(client_t client, size_t len, void *data);
8183

8284
/*
8385
* Finalizes the message. After finalizing the message becomes ready to be sent
8486
* over the corresponding socket, and you may _start() another message.
85-
*
87+
*
8688
* Returns 'true' on success, 'false' otherwise.
8789
*/
8890
bool client_message_finish(client_t client);
8991

92+
/*
93+
* A shortcut to perform all three steps in one, if you only have one number in
94+
* the message.
95+
*
96+
* Returns 'true' on success, 'false' otherwise.
97+
*/
98+
bool client_message_shortcut(client_t client, long long arg);
99+
90100
#endif

0 commit comments

Comments
 (0)