This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, | |
LPSTR lpCmdLine,int nCmdShow) | |
{ | |
lua_State* L = luaL_newstate(); | |
luaL_openlibs(L); | |
luaL_dostring(L, "require \"ezshare\""); | |
lua_getfield(L, LUA_GLOBALSINDEX, "run"); | |
lua_pushlightuserdata (L, hInstance); | |
lua_pushlstring(L, lpCmdLine, strlen(lpCmdLine)); | |
lua_pushinteger(L, nCmdShow); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffi.cdef[[ | |
typedef void* tpeer; | |
tpeer peer_create(int isServer); | |
int peer_broadcast(tpeer peerIn, char* msg, unsigned int size); | |
void peer_destroy(tpeer p); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tpeer peer_create(int isServer) | |
{ | |
init(); | |
speer *p = (speer *)malloc(sizeof(speer)); | |
sockopt_t broadcast=1; | |
if ((p->socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { | |
perror("socket"); | |
exit(1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int peer_broadcast(tpeer peerIn, char* msg, unsigned int size) | |
{ | |
speer* p = mkspeer(peerIn); | |
int val = sendto(p->socket, msg, size, 0, | |
(struct sockaddr *)&p->addr, sizeof p->addr); | |
if (val == -1) { | |
char buf[32]; | |
sprintf(buf, "broadcast %d", WSAGetLastError()); | |
ulog(buf); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct speer { | |
SOCKET socket; | |
struct sockaddr_in addr; | |
} speer; | |
#define mkspeer(tpeer) ((speer *) tpeer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run(hInstance, cmdline, nCmdShow) | |
val, err = pcall(function() _run(hInstance, nCmdShow) end) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function putb(buf, type, where, what) | |
local bp = ffi.cast('uint8_t*', buf) | |
local ptr = ffi.cast(type..'*', bp + where) | |
ptr[0] = what | |
end | |
function getb(buf, type, where) | |
local bp = ffi.cast('uint8_t*', buf) | |
return ffi.cast(type..'*', bp + where)[0] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- header field sizes in bytes | |
local versionsize = 1 | |
local filenamelensize = 2 | |
local contentlensize = 4 | |
local fromsize = 4 | |
local seqsize = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local maxpacketlen=512 | |
local headerlen = versionsize + filenamelensize + | |
contentlensize + fromsize + seqsize | |
local bodylen = maxpacketlen - headerlen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local sendpacketbuf = ffi.new('uint8_t[?]', maxpacketlen) | |
local recvpacketbuf = ffi.new('uint8_t[?]', maxpacketlen) |
OlderNewer