Skip to content

Commit 68164a7

Browse files
committed
rename lib to library.
1 parent 05fe9e8 commit 68164a7

8 files changed

+216
-170
lines changed

build.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ cl %flags% ../login_server.c ../directory.c ../net_windows.c ../wqueue.c /Fe:log
1212

1313
cl %flags% /LD ../game_server_lib.c ../directory.c ../net_windows.c ../wqueue.c /Fe:game_server.dll /link -incremental:no /PDB:game_server_%random%.pdb /EXPORT:on_pevent Ws2_32.lib
1414

15-
cl %flags% ../game_server.c ../net_windows.c ../lib.c /Fe:game_server.exe /link /PDB:game_server.pdb Ws2_32.lib
15+
cl %flags% ../game_server.c ../net_windows.c ../library.c /Fe:game_server.exe /link /PDB:game_server.pdb Ws2_32.lib
1616

1717
popd

directory.c

+22-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
struct directory directory_open(char *path)
1414
{
15+
/*
16+
* Windows implementation.
17+
*/
1518
#ifdef _WIN32
1619
struct directory result = {0};
1720

@@ -27,6 +30,9 @@ struct directory directory_open(char *path)
2730
return result;
2831
#endif
2932

33+
/*
34+
* Linux implementation.
35+
*/
3036
#ifdef __linux__
3137
struct directory result = {0};
3238
result.path = path;
@@ -37,6 +43,9 @@ struct directory directory_open(char *path)
3743

3844
int directory_next(struct directory *directory)
3945
{
46+
/*
47+
* Windows implementation.
48+
*/
4049
#ifdef _WIN32
4150
if (!directory->handle)
4251
return 0;
@@ -57,6 +66,9 @@ int directory_next(struct directory *directory)
5766
return 1;
5867
#endif
5968

69+
/*
70+
* Linux implementation.
71+
*/
6072
#ifdef __linux__
6173
if (!directory->handle)
6274
return 0;
@@ -86,18 +98,26 @@ int directory_next(struct directory *directory)
8698

8799
int directory_create(char *path)
88100
{
101+
/*
102+
* Windows implementation.
103+
*/
89104
#ifdef _WIN32
90105
if (CreateDirectory(path, 0) || GetLastError() == ERROR_ALREADY_EXISTS)
91106
return 1;
107+
108+
return 0;
92109
#endif
93110

111+
/*
112+
* Linux implementation.
113+
*/
94114
#ifdef __linux__
95115
/*
96-
* create directory for read and write.
116+
* Create directory for read and write.
97117
*/
98118
if (mkdir(path, 0666) == 0)
99119
return 1;
100-
#endif
101120

102121
return 0;
122+
#endif
103123
}

directory.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
struct directory {
1010
char *path;
1111

12-
// for iteration.
12+
/*
13+
* For iteration.
14+
*/
1315
int is_directory;
1416
char full_path[512];
1517
char name[256];
@@ -25,8 +27,8 @@ struct directory {
2527
};
2628

2729
#define in_directory(path) \
28-
for (struct directory directory = directory_open(path); directory_next(&directory);) \
29-
if (strcmp(directory.name, ".") != 0 && strcmp(directory.name, "..") != 0)
30+
for (struct directory directory = directory_open(path); directory_next(&directory);) \
31+
if (strcmp(directory.name, ".") != 0 && strcmp(directory.name, "..") != 0)
3032

3133
struct directory directory_open(char *path);
3234
int directory_next(struct directory *directory);

game_server.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,53 @@
1010
#include <unistd.h>
1111
#endif
1212

13-
#include "lib.h"
13+
#include "library.h"
1414
#include "net.h"
1515
#include "pevent.h"
1616

1717
struct state {
1818
void *buf;
19-
struct lib gameserver;
19+
struct library gameserver;
2020
};
2121

2222
static struct state state = {0};
2323

2424
static void handle_net_event(int socket, enum net_event event, void *read, unsigned long long len)
2525
{
26-
enum lstatus lstatus = lfailed;
26+
enum library_status library_status = library_failed;
2727
peventf *on_pevent = 0;
2828
/*
2929
* try loading the library n amount of times.
3030
*/
3131
for (int i = 0; i < 5; i++) {
32-
lstatus = lload(&state.gameserver);
33-
if (lstatus == lneedsreload) {
32+
library_status = library_load(&state.gameserver);
33+
if (library_status == library_needs_reload) {
3434
/*
3535
* before reloading the library, make sure
3636
* to run the before reload event.
3737
*/
38-
on_pevent = (peventf *) lfunction(&state.gameserver, "on_pevent");
38+
on_pevent = (peventf *) library_function(&state.gameserver, "on_pevent");
3939
assert(on_pevent);
4040
on_pevent(&state.buf, pevent_before_reload, 0);
4141
/*
4242
* if the library can't be reloaded, just exit.
4343
*/
44-
lstatus = lload(&state.gameserver);
45-
if (lstatus != lreloaded) {
46-
lstatus = lfailed;
44+
library_status = library_load(&state.gameserver);
45+
if (library_status != library_reloaded) {
46+
library_status = library_failed;
4747
break;
4848
}
4949
/*
5050
* library reloaded! run after reload event.
5151
*/
52-
on_pevent = (peventf *) lfunction(&state.gameserver, "on_pevent");
52+
on_pevent = (peventf *) library_function(&state.gameserver, "on_pevent");
5353
assert(on_pevent);
5454
on_pevent(&state.buf, pevent_after_reload, 0);
5555
}
5656
/*
5757
* the library has been loaded, we can exit the loop.
5858
*/
59-
if (lstatus != lfailed)
59+
if (library_status != library_failed)
6060
break;
6161
/*
6262
* before trying to load again, sleep for a second
@@ -73,13 +73,13 @@ static void handle_net_event(int socket, enum net_event event, void *read, unsig
7373
/*
7474
* if the library couldn't be loaded, crash the server.
7575
*/
76-
if (lstatus == lfailed) {
76+
if (library_status == library_failed) {
7777
fprintf(stderr, "failed to load library.\n");
7878
assert(!"game server library couldn't be loaded");
7979
return;
8080
}
8181

82-
on_pevent = (peventf *) lfunction(&state.gameserver, "on_pevent");
82+
on_pevent = (peventf *) library_function(&state.gameserver, "on_pevent");
8383
assert(on_pevent);
8484

8585
union ppayload payload = {0};
@@ -115,12 +115,12 @@ int main()
115115
state.gameserver.path = "./game_server.so";
116116
#endif
117117

118-
if (lload(&state.gameserver) == lfailed) {
118+
if (library_load(&state.gameserver) == library_failed) {
119119
fprintf(stderr, "failed to load game server library.\n");
120120
return 0;
121121
}
122122

123-
peventf *on_pevent = (peventf *) lfunction(&state.gameserver, "on_pevent");
123+
peventf *on_pevent = (peventf *) library_function(&state.gameserver, "on_pevent");
124124
assert(on_pevent);
125125

126126
if (!on_pevent(&state.buf, pevent_init, 0))

lib.c

-97
This file was deleted.

lib.h

-52
This file was deleted.

0 commit comments

Comments
 (0)