完善 hpsocket

This commit is contained in:
baidwwy 2021-04-13 00:27:21 +08:00
parent e699c519b4
commit 513fc5c545
7 changed files with 367 additions and 243 deletions

View File

@ -3,135 +3,177 @@
EnHandleResult HP_HttpClient::OnConnect(ITcpClient* pSender, CONNID dwConnID)
{
GetCallBack("OnConnect");
lua_pushinteger(L,dwConnID);
lua_call(L,2,1);
return GetResult();
if (GetCallBack("OnConnect"))
{
lua_pushinteger(L, dwConnID);
lua_call(L, 2, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_HttpClient::OnReceive(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnReceive");
lua_pushinteger(L,dwConnID);
lua_pushlstring(L,(const char *)pData,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnReceive"))
{
lua_pushinteger(L, dwConnID);
lua_pushlstring(L, (const char*)pData, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_HttpClient::OnSend(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnSend");
lua_pushinteger(L,dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnSend"))
{
lua_pushinteger(L, dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_HttpClient::OnClose(ITcpClient* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
GetCallBack("OnClose");
lua_pushinteger(L,dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
if (GetCallBack("OnClose"))
{
lua_pushinteger(L, dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
}
lua_pushinteger(L, iErrorCode);
lua_call(L, 4, 1);
return GetResult();
}
lua_pushinteger(L,iErrorCode);
lua_call(L,4,1);
return GetResult();
return HR_OK;
}
EnHttpParseResult HP_HttpClient::OnMessageBegin(IHttpClient* pSender, CONNID dwConnID)
{
GetCallBack("OnMessageBegin");
lua_pushinteger(L,dwConnID);
lua_call(L,2,1);
return GetResult2();
if (GetCallBack("OnMessageBegin"))
{
lua_pushinteger(L, dwConnID);
lua_call(L, 2, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnStatusLine(IHttpClient* pSender, CONNID dwConnID, USHORT usStatusCode, LPCSTR lpszDesc)
{
GetCallBack("OnStatusLine");
lua_pushinteger(L,dwConnID);
lua_pushinteger(L,usStatusCode);
lua_pushstring(L,lpszDesc);
lua_call(L,4,1);
return GetResult2();
if (GetCallBack("OnStatusLine"))
{
lua_pushinteger(L, dwConnID);
lua_pushinteger(L, usStatusCode);
lua_pushstring(L, lpszDesc);
lua_call(L, 4, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnHeader(IHttpClient* pSender, CONNID dwConnID, LPCSTR lpszName, LPCSTR lpszValue)
{
GetCallBack("OnHeader");
lua_pushinteger(L,dwConnID);
lua_pushstring(L,lpszName);
lua_pushstring(L,lpszValue);
lua_call(L,4,1);
return GetResult2();
if (GetCallBack("OnHeader"))
{
lua_pushinteger(L, dwConnID);
lua_pushstring(L, lpszName);
lua_pushstring(L, lpszValue);
lua_call(L, 4, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnHeadersComplete(IHttpClient* pSender, CONNID dwConnID)
{
GetCallBack("OnHeadersComplete");
lua_pushinteger(L,dwConnID);
lua_call(L,2,1);
return GetResult2();
if (GetCallBack("OnHeadersComplete"))
{
lua_pushinteger(L, dwConnID);
lua_call(L, 2, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnBody(IHttpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnBody");
lua_pushinteger(L,dwConnID);
lua_pushlstring(L,(char*)pData,iLength);
lua_call(L,3,1);
return GetResult2();
if (GetCallBack("OnBody"))
{
lua_pushinteger(L, dwConnID);
lua_pushlstring(L, (char*)pData, iLength);
lua_call(L, 3, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnChunkHeader(IHttpClient* pSender, CONNID dwConnID, int iLength)
{
GetCallBack("OnChunkHeader");
lua_pushinteger(L,dwConnID);
lua_pushinteger(L,iLength);
lua_call(L,3,1);
return GetResult2();
if (GetCallBack("OnChunkHeader"))
{
lua_pushinteger(L, dwConnID);
lua_pushinteger(L, iLength);
lua_call(L, 3, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnChunkComplete(IHttpClient* pSender, CONNID dwConnID)
{
GetCallBack("OnChunkComplete");
lua_pushinteger(L,dwConnID);
lua_call(L,2,1);
return GetResult2();
if (GetCallBack("OnChunkComplete"))
{
lua_pushinteger(L, dwConnID);
lua_call(L, 2, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnMessageComplete(IHttpClient* pSender, CONNID dwConnID)
{
GetCallBack("OnMessageComplete");
lua_pushinteger(L,dwConnID);
lua_call(L,2,1);
return GetResult2();
if (GetCallBack("OnMessageComplete"))
{
lua_pushinteger(L, dwConnID);
lua_call(L, 2, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnUpgrade(IHttpClient* pSender, CONNID dwConnID, EnHttpUpgradeType enUpgradeType)
{
GetCallBack("OnUpgrade");
lua_pushinteger(L,dwConnID);
lua_pushinteger(L,enUpgradeType);
lua_call(L,3,1);
return GetResult2();
if (GetCallBack("OnUpgrade"))
{
lua_pushinteger(L, dwConnID);
lua_pushinteger(L, enUpgradeType);
lua_call(L, 3, 1);
return GetResult2();
}
return HPR_OK;
}
EnHttpParseResult HP_HttpClient::OnParseError(IHttpClient* pSender, CONNID dwConnID, int iErrorCode, LPCSTR lpszErrorDesc)
{
GetCallBack("OnParseError");
lua_pushinteger(L,dwConnID);
lua_pushinteger(L,iErrorCode);
lua_pushstring(L,lpszErrorDesc);
lua_call(L,4,1);
return GetResult2();
if (GetCallBack("OnParseError"))
{
lua_pushinteger(L, dwConnID);
lua_pushinteger(L, iErrorCode);
lua_pushstring(L, lpszErrorDesc);
lua_call(L, 4, 1);
return GetResult2();
}
return HPR_OK;
}
@ -391,7 +433,8 @@ static int Creat_HP_HttpClient(lua_State* L){
static int Destroy_HP_HttpClient(lua_State* L){
HP_HttpClient* ud = *(HP_HttpClient**)luaL_checkudata(L,1,"HP_HttpClient");
ud->m_Client->Stop();
lua_pushcfunction(L, Stop);
lua_call(L, 0, 0);
delete ud;
return 0;
}

View File

@ -2,62 +2,80 @@
EnHandleResult HP_PackAgent::OnPrepareConnect(ITcpAgent* pSender, CONNID dwConnID, SOCKET socket)
{
GetCallBack("OnPrepareConnect");
lua_pushinteger(L,dwConnID);
lua_pushinteger(L,socket);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnPrepareConnect"))
{
lua_pushinteger(L, dwConnID);
lua_pushinteger(L, socket);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackAgent::OnConnect(ITcpAgent* pSender, CONNID dwConnID)
{
GetCallBack("OnConnect");
lua_pushinteger(L,dwConnID);
lua_call(L,2,1);
return GetResult();
if (GetCallBack("OnConnect"))
{
lua_pushinteger(L, dwConnID);
lua_call(L, 2, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackAgent::OnReceive(ITcpAgent* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnReceive");
lua_pushinteger(L,dwConnID);
lua_pushlstring(L,(const char*)pData,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnReceive"))
{
lua_pushinteger(L, dwConnID);
lua_pushlstring(L, (const char*)pData, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackAgent::OnSend(ITcpAgent* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnSend");
lua_pushinteger(L,dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnSend"))
{
lua_pushinteger(L, dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackAgent::OnShutdown(ITcpAgent* pSender)
{
GetCallBack("OnShutdown");
lua_call(L,1,1);
return GetResult();
if (GetCallBack("OnShutdown"))
{
lua_call(L, 1, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackAgent::OnClose(ITcpAgent* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
GetCallBack("OnClose");
lua_pushinteger(L,dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
if (GetCallBack("OnClose"))
{
lua_pushinteger(L, dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
}
lua_pushinteger(L, iErrorCode);
lua_call(L, 4, 1);
return GetResult();
}
lua_pushinteger(L,iErrorCode);
lua_call(L,4,1);
return GetResult();
return HR_OK;
}
static BOOL luaL_optboolean (lua_State *L, int arg,BOOL def) {
@ -161,7 +179,11 @@ static int GetRemoteHost(lua_State* L){
//IComplexSocket
static int Stop(lua_State* L){
ITcpPackAgent* Agent = GetAgent(L);
lua_pushboolean(L,Agent->Stop());
SDL_mutex* mutex = *(SDL_mutex**)lua_getextraspace(L);
SDL_UnlockMutex(mutex);
BOOL r = Agent->Stop();
SDL_LockMutex(mutex);
lua_pushboolean(L, r);
return 1;
}
static int Send(lua_State* L){
@ -472,7 +494,8 @@ static int Creat_HP_PackAgent(lua_State* L){
}
static int Destroy_HP_PackAgent(lua_State* L){
HP_PackAgent* ud = *(HP_PackAgent**)luaL_checkudata(L,1,"HP_PackAgent");
ud->m_Agent->Stop();
lua_pushcfunction(L, Stop);
lua_call(L, 0, 0);
delete ud;
return 0;
}

View File

@ -3,55 +3,70 @@
EnHandleResult HP_PackClient::OnPrepareConnect(ITcpClient* pSender,CONNID dwConnID, SOCKET socket)
{
GetCallBack("OnPrepareConnect");
lua_pushinteger(L,dwConnID);
lua_pushinteger(L,socket);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnPrepareConnect"))
{
lua_pushinteger(L, dwConnID);
lua_pushinteger(L, socket);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackClient::OnConnect(ITcpClient* pSender, CONNID dwConnID)
{
GetCallBack("OnConnect");
lua_pushinteger(L,dwConnID);
lua_call(L,2,1);
return GetResult();
if (GetCallBack("OnConnect"))
{
lua_pushinteger(L, dwConnID);
lua_call(L, 2, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackClient::OnReceive(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnReceive");
lua_pushinteger(L,dwConnID);
lua_pushlstring(L,(const char *)pData,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnReceive"))
{
lua_pushinteger(L, dwConnID);
lua_pushlstring(L, (const char*)pData, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackClient::OnSend(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnSend");
lua_pushinteger(L,dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnSend"))
{
lua_pushinteger(L, dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackClient::OnClose(ITcpClient* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
GetCallBack("OnClose");
lua_pushinteger(L,dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
if (GetCallBack("OnClose"))
{
lua_pushinteger(L, dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
}
lua_pushinteger(L, iErrorCode);
lua_call(L, 4, 1);
return GetResult();
}
lua_pushinteger(L,iErrorCode);
lua_call(L,4,1);
return GetResult();
return HR_OK;
}
@ -98,7 +113,8 @@ static int Creat_HP_PackClient(lua_State* L){
static int Destroy_HP_PackClient(lua_State* L){
HP_PackClient* ud = *(HP_PackClient**)luaL_checkudata(L,1,"HP_PackClient");
ud->m_Client->Stop();
lua_pushcfunction(L, Stop);
lua_call(L, 0, 0);
delete ud;
return 0;
}

View File

@ -2,63 +2,80 @@
EnHandleResult HP_PackServer::OnPrepareListen(ITcpServer* pSender, SOCKET soListen)
{
GetCallBack("OnPrepareListen");
lua_pushinteger(L,soListen);
lua_call(L,2,1);
return GetResult();
if (GetCallBack("OnPrepareListen"))
{
lua_pushinteger(L, soListen);
lua_call(L, 2, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackServer::OnAccept(ITcpServer* pSender, CONNID dwConnID, UINT_PTR soSvrent)
{
GetCallBack("OnAccept");
lua_pushinteger(L,dwConnID);
lua_pushinteger(L,soSvrent);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnAccept"))
{
lua_pushinteger(L, dwConnID);
lua_pushinteger(L, soSvrent);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackServer::OnReceive(ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnReceive");
lua_pushinteger(L,dwConnID);
lua_pushlstring(L,(const char*)pData,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnReceive"))
{
lua_pushinteger(L, dwConnID);
lua_pushlstring(L, (const char*)pData, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackServer::OnSend(ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
GetCallBack("OnSend");
lua_pushinteger(L,dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L,iLength);
lua_call(L,3,1);
return GetResult();
if (GetCallBack("OnSend"))
{
lua_pushinteger(L, dwConnID);
//lua_pushlightuserdata(L,(void*)pData);
lua_pushinteger(L, iLength);
lua_call(L, 3, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackServer::OnShutdown(ITcpServer* pSender)
{
GetCallBack("OnShutdown");
lua_call(L,1,1);
return GetResult();
if (GetCallBack("OnShutdown"))
{
lua_call(L, 1, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_PackServer::OnClose(ITcpServer* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
GetCallBack("OnClose");
lua_pushinteger(L,dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
if (GetCallBack("OnClose"))
{
lua_pushinteger(L, dwConnID);
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
}
lua_pushinteger(L, iErrorCode);
lua_call(L, 4, 1);
return GetResult();
}
lua_pushinteger(L,iErrorCode);
lua_call(L,4,1);
return GetResult();
return HR_OK;
}
static BOOL luaL_optboolean (lua_State *L, int arg,BOOL def) {
@ -493,7 +510,8 @@ static int Creat_HP_PackServer(lua_State* L){
static int Destroy_HP_PackServer(lua_State* L){
HP_PackServer* ud = *(HP_PackServer**)luaL_checkudata(L,1,"HP_PackServer");
ud->m_Server->Stop();
lua_pushcfunction(L, Stop);
lua_call(L, 0, 0);
delete ud;
return 0;
}

View File

@ -136,21 +136,21 @@ int GetLastError(lua_State* L) {
ITcpClient* cli = GetTcpClient(L);
switch (cli->GetLastError()) {
CASE(SE_OK)
CASE(SE_ILLEGAL_STATE)
CASE(SE_INVALID_PARAM)
CASE(SE_SOCKET_CREATE)
CASE(SE_SOCKET_BIND)
CASE(SE_SOCKET_PREPARE)
CASE(SE_SOCKET_LISTEN)
CASE(SE_CP_CREATE)
CASE(SE_WORKER_THREAD_CREATE)
CASE(SE_DETECT_THREAD_CREATE)
CASE(SE_SOCKE_ATTACH_TO_CP)
CASE(SE_CONNECT_SERVER)
CASE(SE_NETWORK)
CASE(SE_DATA_PROC)
CASE(SE_DATA_SEND)
CASE(SE_SSL_ENV_NOT_READY)
CASE(SE_ILLEGAL_STATE)
CASE(SE_INVALID_PARAM)
CASE(SE_SOCKET_CREATE)
CASE(SE_SOCKET_BIND)
CASE(SE_SOCKET_PREPARE)
CASE(SE_SOCKET_LISTEN)
CASE(SE_CP_CREATE)
CASE(SE_WORKER_THREAD_CREATE)
CASE(SE_DETECT_THREAD_CREATE)
CASE(SE_SOCKE_ATTACH_TO_CP)
CASE(SE_CONNECT_SERVER)
CASE(SE_NETWORK)
CASE(SE_DATA_PROC)
CASE(SE_DATA_SEND)
CASE(SE_SSL_ENV_NOT_READY)
}
return 1;
}

View File

@ -2,58 +2,73 @@
EnHandleResult HP_UdpNode::OnPrepareListen(IUdpNode* pSender, SOCKET soListen)
{
GetCallBack("OnPrepareListen");
lua_pushinteger(L,soListen);
lua_call(L,2,1);
return GetResult();
if (GetCallBack("OnPrepareListen"))
{
lua_pushinteger(L, soListen);
lua_call(L, 2, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_UdpNode::OnSend(IUdpNode* pSender, LPCTSTR lpszRemoteAddress, USHORT usRemotePort, const BYTE* pData, int iLength)
{
GetCallBack("OnSend");
lua_pushstring(L,lpszRemoteAddress);
lua_pushinteger(L,usRemotePort);
//lua_pushlightuserdata(L,(void *)pData);
lua_pushinteger(L,iLength);
lua_call(L,4,1);
return GetResult();
if (GetCallBack("OnSend"))
{
lua_pushstring(L, lpszRemoteAddress);
lua_pushinteger(L, usRemotePort);
//lua_pushlightuserdata(L,(void *)pData);
lua_pushinteger(L, iLength);
lua_call(L, 4, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_UdpNode::OnReceive(IUdpNode* pSender, LPCTSTR lpszRemoteAddress, USHORT usRemotePort, const BYTE* pData, int iLength)
{
GetCallBack("OnReceive");
lua_pushstring(L,lpszRemoteAddress);
lua_pushinteger(L,usRemotePort);
lua_pushlstring(L,(const char *)pData,iLength);
lua_call(L,4,1);
return GetResult();
if (GetCallBack("OnReceive"))
{
lua_pushstring(L, lpszRemoteAddress);
lua_pushinteger(L, usRemotePort);
lua_pushlstring(L, (const char*)pData, iLength);
lua_call(L, 4, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_UdpNode::OnError(IUdpNode* pSender, EnSocketOperation enOperation, int iErrorCode, LPCTSTR lpszRemoteAddress, USHORT usRemotePort, const BYTE* pBuffer, int iLength)
{
GetCallBack("OnError");
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
}
lua_pushinteger(L,iErrorCode);
lua_pushstring(L,lpszRemoteAddress);
lua_pushinteger(L,usRemotePort);
lua_pushlstring(L,(const char *)pBuffer,iLength);
if (GetCallBack("OnError"))
{
switch (enOperation) {
CASE(SO_UNKNOWN)
CASE(SO_ACCEPT)
CASE(SO_CONNECT)
CASE(SO_SEND)
CASE(SO_RECEIVE)
CASE(SO_CLOSE)
}
lua_pushinteger(L, iErrorCode);
lua_pushstring(L, lpszRemoteAddress);
lua_pushinteger(L, usRemotePort);
lua_pushlstring(L, (const char*)pBuffer, iLength);
lua_call(L,6,1);
return GetResult();
lua_call(L, 6, 1);
return GetResult();
}
return HR_OK;
}
EnHandleResult HP_UdpNode::OnShutdown(IUdpNode* pSender)
{
GetCallBack("OnShutdown");
lua_call(L,1,1);
return GetResult();
if (GetCallBack("OnShutdown"))
{
lua_call(L, 1, 1);
return GetResult();
}
return HR_OK;
}
@ -77,7 +92,11 @@ static int Start(lua_State* L){
static int Stop(lua_State* L){
IUdpNode* Udp = GetUdpNode(L);
lua_pushboolean(L,Udp->Stop());
SDL_mutex* mutex = *(SDL_mutex**)lua_getextraspace(L);
SDL_UnlockMutex(mutex);
BOOL r = Udp->Stop();
SDL_LockMutex(mutex);
lua_pushboolean(L, r);
return 1;
}
@ -320,7 +339,8 @@ static int Creat_HP_UdpNode(lua_State* L){
static int Destroy_HP_UdpNode(lua_State* L){
HP_UdpNode* ud = *(HP_UdpNode**)luaL_checkudata(L,1,"HP_UdpNode");
ud->m_UdpNode->Stop();
lua_pushcfunction(L, Stop);
lua_call(L, 0, 0);
delete ud;
return 0;
}

View File

@ -14,7 +14,6 @@ class HP_Base
public:
HP_Base(lua_State* L){
m_self = luaL_ref(L,LUA_REGISTRYINDEX);
m_mutex = *(HP_mutex **)lua_getextraspace(L);
m_L = L;
};
@ -22,12 +21,17 @@ public:
luaL_unref(m_L,LUA_REGISTRYINDEX,m_self);
};
void GetCallBack(const char* name){
HP_LockMutex(m_mutex);
L = lua_newthread(m_L);
lua_rawgeti(L, LUA_REGISTRYINDEX, m_self);
lua_getfield(L,-1,name);
lua_insert(L,1);//self
int GetCallBack(const char* name){
m_mutex = *(HP_mutex**)lua_getextraspace(m_L);
if (HP_LockMutex(m_mutex))
{
L = lua_newthread(m_L);
lua_rawgeti(L, LUA_REGISTRYINDEX, m_self);
lua_getfield(L, -1, name);
lua_insert(L, 1);//self
return 1;
}
return 0;
};
EnHandleResult GetResult(){