예제 #1
0
void mwSession_start(struct mwSession *s) {
  struct mwMsgHandshake *msg;
  int ret;

  g_return_if_fail(s != NULL);
  g_return_if_fail(mwSession_isStopped(s));

  if(mwSession_isStarted(s) || mwSession_isStarting(s)) {
    g_debug("attempted to start session that is already started/starting");
    return;
  }
  
  state(s, mwSession_STARTING, 0);

  msg = (struct mwMsgHandshake *) mwMessage_new(mwMessage_HANDSHAKE);
  msg->major = GUINT(property_get(s, mwSession_CLIENT_VER_MAJOR));
  msg->minor = GUINT(property_get(s, mwSession_CLIENT_VER_MINOR));
  msg->login_type = GUINT(property_get(s, mwSession_CLIENT_TYPE_ID));

  msg->loclcalc_addr = GUINT(property_get(s, mwSession_CLIENT_IP));

  if(msg->major >= 0x001e && msg->minor >= 0x001d) {
    msg->unknown_a = 0x0100;
    msg->local_host = property_get(s, mwSession_CLIENT_HOST);
  }

  ret = mwSession_send(s, MW_MESSAGE(msg));
  mwMessage_free(MW_MESSAGE(msg));

  if(ret) {
    mwSession_stop(s, CONNECTION_BROKEN);
  } else {
    state(s, mwSession_HANDSHAKE, 0);
  }
}
예제 #2
0
void __cdecl KeepAliveThread(LPVOID param)
{
	CSametimeProto* proto = (CSametimeProto*)param;
	int i = 120;
	proto->debugLog(_T("KeepAliveThread() start"));

	while (1) {

		if (i <= 0) {
			i = 120;
			// send keepalive every 120 * 250 = 30000[ms]
			if (mwSession_isStarted(proto->session) && proto->session) {
				mwSession_sendKeepalive(proto->session);
			}
		}

		i--;

		SleepEx(250, TRUE);

		EnterCriticalSection(&(proto->session_cs));
		if (Miranda_Terminated() || !proto->session) {
			LeaveCriticalSection(&(proto->session_cs));
			proto->debugLog(_T("KeepAliveThread() end"));
			break;
		}
		LeaveCriticalSection(&(proto->session_cs));
	}

	return;
}
bool MeanwhileSession::isConnected()
{
    return mwSession_isStarted(session);
}