}\
(convPtr)[0] = L'\0'
-
-/*
-#define convertTEXT(buf,basePtr,convPtr,endPtr)\
- (buf) = (convPtr);\
- for(;(basePtr) < (endPtr);(basePtr)++){\
- switch(basePtr[0]){\
- case L'&':\
- strcpy((convPtr),"&");\
- (convPtr) += strlen(convPtr);\
- break;\
- case L'<':\
- strcpy((convPtr),"<");\
- (convPtr) += strlen(convPtr);\
- break;\
- case L'>':\
- strcpy((convPtr),">");\
- (convPtr) += strlen(convPtr);\
- break;\
- case L'\"':\
- strcpy((convPtr),""");\
- (convPtr) += strlen(convPtr);\
- break;\
- case L'\'':\
- strcpy((convPtr),"'");\
- (convPtr) += strlen(convPtr);\
- break;\
- default:\
- WideCharToMultiByte(CP_UTF8,0,(basePtr),1,(convPtr),LENGTH_1024,(LPCSTR)NULL,(LPBOOL)NULL);\
- (convPtr) += strlen(convPtr);\
- break;\
- }\
- }\
- (convPtr)[0] = '\0'
-*/
-
-
-
-
#define getBaseVpos(server_time,base_time) (((server_time) - (base_time)) * 100)
#define setMsec(mSec)\
///
static unsigned int WINAPI NicoLiveKeapALiveThread(void* lpBuffer);
+
+
+
///
///\83`\83\83\83b\83g\8eó\90M\83\8b\81[\83v\8aÖ\90\94
///
static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self);
+///
+///\83\8b\81[\83v
+///
+static unsigned int loopCommon(NicoLiveStream_P self,WSAEVENT sendEvent,WSAEVENT resetEvent ,NicoLiveOnSend nicoLiveOnSend);
///
///\83R\83\81\83\93\83g\89ð\90Í\8aÖ\90\94
static void NicoLiveError(void *buf);
static void NicoLiveSelfDisconnect(void *buf);
+
+static VOID OnSendHeartBeat(NicoLiveStream_P self);
+
+static VOID OnSendKeepAllive(NicoLiveStream_P self);
///
///\83\\83P\83b\83g\8eæ\93¾\8aÖ\90\94
///
//\90¶\90¬&\8f\89\8aú\89»
NicoLiveStream_P self = (NicoLiveStream_P)calloc(1,sizeof(NicoLiveStream));
+ //\8f\89\8aú\92l\82Ì\90Ý\92è
+ self->chatManager.onHeartBeatSend = OnSendHeartBeat;
+
+ self->chatManager.onKeepAlliveSend = OnSendKeepAllive;
+
+ InitializeCriticalSection(&self->sessionManager.cs);
+
+ self->chatManager.heartBeatTime = 300000;
+
+ self->chatManager.heartBeatFlag = TRUE;
+
+ self->chatManager.keepAliveTime = 300000;
+
+ self->chatManager.keapALiveFlag = TRUE;
+
self->chatManager.endEvent = WSACreateEvent();
self->chatManager.startEvent = WSACreateEvent();
self->chatManager.resetEvents[2] = WSACreateEvent();
+
+
+
+
+ //\83X\83\8c\83b\83h\82Ì\8aJ\8en
self->chatManager.hRecvChatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveRecvChat,self,0,&self->chatManager.recvChatThreadID);
self->chatManager.hHeartBeatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveHeartBeatThread,self,0,&self->chatManager.heartBeatThreadID);
self->chatManager.hKeapALiveHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveKeapALiveThread,self,0,&self->chatManager.keapALiveThreadID);
- self->chatManager.heartBeatTime = 300000;
-
- self->chatManager.heartBeatFlag = TRUE;
- self->chatManager.keepAliveTime = 300000;
- self->chatManager.keapALiveFlag = TRUE;
+
- InitializeCriticalSection(&self->sessionManager.cs);
+
dumpln(TEXT("size%d"),sizeof(NicoLiveStream));
NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
- WSAEVENT events[3] = {self->chatManager.deleteEvent,self->chatManager.startEvent,self->chatManager.endEvent}; //\83C\83x\83\93\83g\94z\97ñ
- WSAEVENT streamEvent[2] = {self->chatManager.endEvent,self->chatManager.setKeepAliveTimeEvent};
- DWORD dwResult; //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
- DWORD endResult;
-
- while(TRUE){
-restart:
- WSASetEvent(self->chatManager.resetEvents[2]);
-
- dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
-
-
- //\83G\83\89\81[\82Ì\8fê\8d\87
- if(dwResult == WSA_WAIT_FAILED){
-
- goto err;
- }
-
-
- switch(dwResult - WSA_WAIT_EVENT_0){
+ rslt = loopCommon(self,self->chatManager.setKeepAliveTimeEvent,self->chatManager.resetEvents[2],self->chatManager.onKeepAlliveSend);
- case 0:
-
- goto end;
-
- case 1:
- WSAResetEvent(self->chatManager.resetEvents[2]);
- break;
-
- case 2:
- continue;
-
-
- default:
-
- goto err;
-
- }
-
- while(TRUE){
- WSAResetEvent(self->chatManager.setKeepAliveTimeEvent);
- endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.keepAliveTime,FALSE);
-
- if(endResult == WSA_WAIT_TIMEOUT){
+ _endthreadex(rslt);
- if(self->chatManager.keapALiveFlag){
- LPCWSTR mail[2] = {L"184",NULL};
- NicoLiveStream_sendChat(self,L"/keapalive",mail,NULL);
- }
- } else{
- switch(endResult - WSA_WAIT_EVENT_0){
+ return rslt;
+}
- case 0:
- goto restart;
+static unsigned int WINAPI NicoLiveHeartBeatThread(void* lpBuffer){
- case 1:
- break;
+ unsigned int rslt = 0;
- default:
- goto err;
+ NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
- }
- }
- }
+ rslt = loopCommon(self,self->chatManager.setHeartBeatTimeEvent,self->chatManager.resetEvents[1],self->chatManager.onHeartBeatSend);
- }
-
-err:
- _beginthread(NicoLiveError,0,self);
-
-end:
_endthreadex(rslt);
return rslt;
}
+static unsigned int loopCommon(NicoLiveStream_P self,WSAEVENT sendEvent,WSAEVENT resetEvent ,NicoLiveOnSend nicoLiveOnSend){
-static unsigned int WINAPI NicoLiveHeartBeatThread(void* lpBuffer){
-
- unsigned int rslt = 0;
-
- NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
-
+ unsigned int rslt;
WSAEVENT events[3] = {self->chatManager.deleteEvent,self->chatManager.startEvent,self->chatManager.endEvent}; //\83C\83x\83\93\83g\94z\97ñ
- WSAEVENT streamEvent[2] = {self->chatManager.endEvent,self->chatManager.setHeartBeatTimeEvent};
+ WSAEVENT streamEvent[2] = {self->chatManager.endEvent,sendEvent};
DWORD dwResult; //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
DWORD endResult;
while(TRUE){
restart:
- WSASetEvent(self->chatManager.resetEvents[1]);
+ WSASetEvent(resetEvent);
dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
goto end;
case 1:
- WSAResetEvent(self->chatManager.resetEvents[1]);
+ WSAResetEvent(resetEvent);
break;
case 2:
}
while(TRUE){
- WSAResetEvent(self->chatManager.setHeartBeatTimeEvent);
+ WSAResetEvent(sendEvent);
endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.heartBeatTime,FALSE);
if(endResult == WSA_WAIT_TIMEOUT){
- if(self->chatManager.heartBeatFlag){
- NicoLiveStream_sendHeartBeat(self);
- }
+ nicoLiveOnSend(self);
+ //dumpln(TEXT("onSend"));
+
+ _heapmin();
} else{
switch(endResult - WSA_WAIT_EVENT_0){
}
+end:
+ return rslt;
+
err:
_beginthread(NicoLiveError,0,self);
+ rslt = 1;
+ goto end;
+}
-end:
+static VOID OnSendHeartBeat(NicoLiveStream_P self){
- _endthreadex(rslt);
+ if(self->chatManager.heartBeatFlag){
+ NicoLiveStream_sendHeartBeat(self);
+ }
- return rslt;
}
+static VOID OnSendKeepAllive(NicoLiveStream_P self){
+
+ if(self->chatManager.keapALiveFlag){
+ LPCWSTR mail[2] = {L"184",NULL};
+ NicoLiveStream_sendChat(self,L"/keapalive",mail,NULL);
+ }
+
+}
#define NICOLIVE_RECEVE_CHAT_LENGTH LENGTH_2048
#define NICOLIVE_REQUEST_CHAT_LENGTH LENGTH_256
}
+
+
+
static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self){
}
+
+
static VOID NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_PTR endSize,LPWSTR* mailCountBuf,SIZE_T* mailCountBufSize,SIZE_T* commentCountSum,SIZE_T* commentBufSize){
LPWSTR indexPtr; //\89ð\90Í\8e\9e\82Ì\8ew\95W\83|\83C\83\93\83^
}
+
+
static void NicoLiveError(void *buf){
NicoLiveStream_P nl = (NicoLiveStream_P)buf;