• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ CloseConnection函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中CloseConnection函数的典型用法代码示例。如果您正苦于以下问题:C++ CloseConnection函数的具体用法?C++ CloseConnection怎么用?C++ CloseConnection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了CloseConnection函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: DoRead

BOOL DoRead(PCLIENT pClient)
{
    SetLastError(NO_ERROR);
    DWORD nBytes = 0;
    BOOL b = ReadFile(pClient->hPipe, &pClient->Message, sizeof(pClient->Message),
                      &nBytes, pClient);

    DWORD error = GetLastError();

    if (b && error == NO_ERROR) {
        return TRUE;
    }
    if (error == ERROR_BROKEN_PIPE) {
        pClient->LogMessageV("<!-- **** ReadFile 002 *** ERROR_BROKEN_PIPE [%d] -->\n", nBytes);
        CloseConnection(pClient);
        return TRUE;
    }
    else if (error == ERROR_INVALID_HANDLE) {
        // ?
        pClient->LogMessageV("<!-- **** ReadFile 002 *** ERROR_INVALID_HANDLE -->\n");
        // I have no idea why this happens.  Our remedy is to drop the connection.
        return TRUE;
    }
    else if (error != ERROR_IO_PENDING) {
        if (b) {
            pClient->LogMessageV("<!-- **** ReadFile 002 succeeded: %d -->\n", error);
        }
        else {
            pClient->LogMessageV("<!-- **** ReadFile 002 failed: %d -->\n", error);
        }
        CloseConnection(pClient);
    }
    return TRUE;
}
开发者ID:qeedquan,项目名称:game_format_dumpers,代码行数:34,代码来源:tracebld.cpp


示例2: NS_ABORT_IF_FALSE

NS_IMETHODIMP
WebSocket::OnServerClose(nsISupports *aContext, uint16_t aCode,
                           const nsACString &aReason)
{
  NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");

  MOZ_ASSERT(mReadyState != WebSocket::CONNECTING,
             "Received server close before connected?");
  MOZ_ASSERT(mReadyState != WebSocket::CLOSED,
             "Received server close after already closed!");

  // store code/string for onclose DOM event
  mCloseEventCode = aCode;
  CopyUTF8toUTF16(aReason, mCloseEventReason);

  if (mReadyState == WebSocket::OPEN) {
    // Server initiating close.
    // RFC 6455, 5.5.1: "When sending a Close frame in response, the endpoint
    // typically echos the status code it received".
    // But never send certain codes, per section 7.4.1
    if (aCode == 1005 || aCode == 1006 || aCode == 1015) {
      CloseConnection(0, EmptyCString());
    } else {
      CloseConnection(aCode, aReason);
    }
  } else {
    // We initiated close, and server has replied: OnStop does rest of the work.
    MOZ_ASSERT(mReadyState == WebSocket::CLOSING, "unknown state");
  }

  return NS_OK;
}
开发者ID:LyeSS,项目名称:mozilla-central,代码行数:32,代码来源:WebSocket.cpp


示例3: CloseConnection

BOOL CTransmission::OpenConnection() {
    if (this->isConnected == true && m_pServer != nullptr) {
        return TRUE;
    }

    if (this->m_pListener == nullptr) {
        return FALSE;
    }

    if (m_pServer != nullptr) {
        CloseConnection();
    }

    this->m_pServer = new CTcpServerPtr(this->m_pListener);

    if ((*m_pServer) == nullptr) {
        return FALSE;
    }

    ((this->m_pServer)->Get())->SetWorkerThreadCount(1);
    BOOL state = (*m_pServer)->Start(L"0.0.0.0", 55999);

    if (state == FALSE) {
        EnSocketError error = (*m_pServer)->GetLastError();
        CloseConnection();

    } else {
        this->isConnected = true;
    }

    return  state;
}
开发者ID:richarddan,项目名称:ImageMeasure,代码行数:32,代码来源:Transmission.cpp


示例4: CloseConnection

void WebSocketWorker::doRead()
{
    if (!m_isRunning)
        return;

    if (!m_webSocketServer.IsRunning() || !m_socket->isOpen())
    {
        CloseConnection();
        return;
    }

    if (m_webSocketMode)
    {
        ProcessFrames(m_socket);
    }
    else
    {
        if (!ProcessHandshake(m_socket))
            SendClose(kCloseProtocolError);
    }

    if (!m_webSocketMode)
    {
        LOG(VB_HTTP, LOG_WARNING, "WebSocketServer: Timed out waiting for connection upgrade");
        CloseConnection();
    }
}
开发者ID:garybuhrmaster,项目名称:mythtv,代码行数:27,代码来源:websocket.cpp


示例5: UnregisterServer

void UnregisterServer(void)
{
	if (con_state != MSCS_REGISTERED)
	{
		con_state = MSCS_NONE;
		CloseConnection();
		return;
	}

	con_state = MSCS_NONE;

	CONS_Printf("Unregistering this server to the master server...\n");

	if (MS_Connect(registered_server.ip, registered_server.port, 0))
	{
		CONS_Printf("cannot connect to the master server\n");
		return;
	}

	if (RemoveFromMasterSever() < 0)
		CONS_Printf("cannot remove this server from the master server\n");

	CloseConnection();
	MSCloseUDPSocket();
	MSLastPing = 0;
}
开发者ID:Pupswoof117,项目名称:SRB2-Public,代码行数:26,代码来源:mserv.c


示例6: recv

void
FCGXStream::FillBuffer()
{
    if (mFD == INVALID_SOCKET)
        return;

    mRecvOut = 0;
    int amt;
    do {
       amt = recv(mFD, (char*)mRecvBuf + mRecvIn, FCGXBUFSIZE - mRecvIn, 0);
    } while (amt < 0 &&
#ifdef _WIN32
        WSAGetLastError() == WSAEINTR
#else
        errno == EINTR
#endif
        );
    if (amt < 0) {
        LogFatal("FCGXStream::FillBuffer(): Could not read data from socket");
        CloseConnection(true);
    } else if (amt == 0) {
        LogFatal("Unexpected connection close.");
        CloseConnection(true);
    } else {
        mRecvIn += amt;
    }
}
开发者ID:aptana,项目名称:Jaxer,代码行数:27,代码来源:FCGXStream.cpp


示例7: recv

int ClientNetwork::ReceivePacketNonBlocking( char *recvbuf, unsigned int BufferSize )
{
	int WriteIndex = 0;
	int SumRead = 0;
	int RequiredRead = 0;
	do{
TRY_MORE_READ_ON_LACK_OF_DATA:
//		unsigned int Start = GetTimer();
		if( WriteIndex == 0 )
			iResult = recv( ConnectSocket, &recvbuf[WriteIndex], sizeof( NetworkPacketHeader ), 0 );
		else
		{
			int SpaceLeftInOurBuffer = BufferSize - WriteIndex;
			int RemainingToRead = RequiredRead - SumRead;
			int ActualRead = RemainingToRead;
			if( ActualRead > SpaceLeftInOurBuffer )
				ActualRead = SpaceLeftInOurBuffer;
			iResult = recv( ConnectSocket, &recvbuf[WriteIndex], ActualRead, 0 );
		}

		if ( iResult == 0 )
		{
			printf( "Connection closed\n" );
			CloseConnection();
	//		exit(1);
			return iResult;
		}
		else if( iResult < 0 )
		{
			int iResult2 = WSAGetLastError();
			if( iResult2 == WSAEWOULDBLOCK )
			{
				Sleep( 1 );
				printf( "Need more data from server\n" );
				goto TRY_MORE_READ_ON_LACK_OF_DATA;
//				return 0;
			}
			printf( "recv failed: %d - %d\n", iResult, iResult2 );
			CloseConnection();
	//		exit(1);
			return iResult;
		}
		if( WriteIndex == 0 )
		{
			NetworkPacketHeader *ph = (NetworkPacketHeader *)recvbuf;
			RequiredRead = (int)ph->PacketSize;
			if( (int)BufferSize < RequiredRead )
			{
				assert( false );
				return 0;
			}
		}
		WriteIndex += iResult;
		SumRead += iResult;
//		unsigned int End = GetTimer();
//		printf("network packet fragment size %d, received in %d seconds\n", iResult, End - Start );
	}while( SumRead < RequiredRead && BufferSize - WriteIndex > 0 );
    return SumRead;
}
开发者ID:RuschGaming,项目名称:NetworkImageProcessing,代码行数:59,代码来源:ClientNetwork.cpp


示例8: WorkerThread

DWORD WINAPI WorkerThread(LPVOID pvVoid)
{
    PCLIENT pClient;
    BOOL b;
    LPOVERLAPPED lpo;
    DWORD nBytes;
    HANDLE hCompletionPort = (HANDLE)pvVoid;

    for (BOOL fKeepLooping = TRUE; fKeepLooping;) {
        pClient = NULL;
        lpo = NULL;
        nBytes = 0;
        b = GetQueuedCompletionStatus(hCompletionPort,
                                      &nBytes, (PULONG_PTR)&pClient, &lpo, INFINITE);

        if (!b) {
            if (pClient) {
                if (GetLastError() == ERROR_BROKEN_PIPE) {
                    pClient->LogMessageV("<!-- Client closed pipe. -->");
                }
                else {
                    pClient->LogMessageV("<!-- *** GetQueuedCompletionStatus failed %d -->",
                                         GetLastError());
                }
                CloseConnection(pClient);
            }
            continue;
        }

        if (pClient->fAwaitingAccept) {
            BOOL fAgain = TRUE;
            while (fAgain) {
                LONG nClient = InterlockedIncrement(&s_nTotalClients);
                InterlockedIncrement(&s_nActiveClients);
                pClient->fAwaitingAccept = FALSE;

                PCLIENT pNew = CreatePipeConnection(hCompletionPort, nClient);

                fAgain = FALSE;
                if (pNew != NULL) {
                    fAgain = !pNew->fAwaitingAccept;
                    DoRead(pNew);
                }
            }
        }
        else {
            if (nBytes <= offsetof(TBLOG_MESSAGE, szMessage)) {
                pClient->LogMessageV("</t:Process>\n");
                CloseConnection(pClient);
                continue;
            }
            pClient->LogMessage(&pClient->Message, nBytes);
        }

        DoRead(pClient);
    }
    return 0;
}
开发者ID:qeedquan,项目名称:game_format_dumpers,代码行数:58,代码来源:tracebld.cpp


示例9: ClientThread

unsigned __stdcall ClientThread(void *pVoid)
{
	int nRet;
	BYTE buf[1024];
	LPREQUEST lpReq = (LPREQUEST)pVoid;

	//
	// Count this client
	//
	IncrementClientCount();

	//
	// Recv the request data
	//
	if (!RecvRequest(lpReq, buf, sizeof(buf)))
	{
		CloseConnection(lpReq);
		free(lpReq);
		DecrementClientCount();
		return 0;
	}

	//
	// Parse the request info
	//
	nRet = ParseRequest(lpReq, buf);
	if (nRet)
	{
		SendError(lpReq, nRet);
		CloseConnection(lpReq);
		free(lpReq);
		DecrementClientCount();
		return 0;
	}

	//
	// Send the file to the client
	//
	SendFile(lpReq);

	//
	// Clean up
	CloseConnection(lpReq);
	free(pVoid);

	//
	// Subtract this client
	//
	DecrementClientCount();
	return 0;
}
开发者ID:Budskii,项目名称:ulib-win,代码行数:51,代码来源:httpmt.c


示例10: OpenSocketServer

// creates a connection and destroys it again
enum TVerdict TE_RConnectionTest301::doTestStepL(void)
{
	TInt err;

	RConnection activeConn;
	RConnection conn;
	RSocketServ ss;

	TRequestStatus status;
	TInterfaceNotificationBuf info;

	err = OpenSocketServer(ss);
	TESTEL(KErrNone == err, err);
	CleanupClosePushL(ss);

	err = OpenConnection(conn, ss);
	TESTEL(KErrNone == err, err);
	CleanupClosePushL(conn);

	err = OpenConnection(activeConn, ss);
	TESTEL(KErrNone == err, err);
	CleanupClosePushL(activeConn);

	err = StartConnectionWithOverrides(conn, 1);
	TESTEL(KErrNone == err, err);

	// issue request
	AllInterfaceNotification(conn, status, info);

	// start another different connection to complete request if it hasn't already done so
	err = StartConnectionWithOverrides(activeConn, 6);
	TESTEL(KErrNone == err, err);

	// wait for completion
	User::WaitForRequest(status);

	// check for correct value
	TESTEL(status.Int() == KErrInUse, status.Int());

	CloseConnection(activeConn);
	CleanupStack::Pop();

	CloseConnection(conn);
	CleanupStack::Pop();

	CloseSocketServer(ss);
	CleanupStack::Pop();

	return TestStepResult();

} // TE_RConnectionTest301
开发者ID:cdaffara,项目名称:symbiandump-os1,代码行数:52,代码来源:TE_AllInterfaceNotification.cpp


示例11: GetUrl

int
GetUrl(char *url, char **reply_ret, int *len_ret)
{
    char *hostname, *path;
    int port;
    XtransConnInfo trans;
    int status = 0;

    if (ParseHttpUrl(url, &hostname, &port, &path) != 0)
	return 1;		/* invalid URL */

    trans = OpenConnection(hostname, port);
    if (trans == NULL) {
	status = 1;		/* connection failed */
	goto end;
    }

    SendGetRequest(trans, path);

    *len_ret = ReadGetReply(trans, reply_ret);

    CloseConnection(trans);

end:
    Free(hostname);
    Free(path);
    return status;
}
开发者ID:rickgaiser,项目名称:xfree86-ps2,代码行数:28,代码来源:GetUrl.c


示例12: connect

// ----------------------------------------------------------------------
void MyServer::slotNewConnection()
{
// если уже подключено максималное количество пользователей - отсоединяем всех новых
    if (i>=4)
    {
        QTcpSocket* pClientSocket_err = m_ptcpServer->nextPendingConnection();

        pClientSocket_err->close();

        return;
    }
// если пришел, запрос на подключение и у нас еще есть места для пользователей - создаем сокет для общения с ним
// и отправляем ему код для кодирования сообщения

    QTcpSocket* pClientSocket = m_ptcpServer->nextPendingConnection();

    connect(pClientSocket, SIGNAL(disconnected()) , this , SLOT(CloseConnection( pClientSocket)));

    connect(pClientSocket, SIGNAL(readyRead()), this , SLOT(slotReadClient()));

    for ( int j = 0; j < 4 ; j++ )
      if(clients[i].my_client == NULL)
        {
          clients[i].my_client = pClientSocket;

          clients[i].code = get_cdma_code();

          sendToClient_code(&clients[i] );

          i++;
          break;
        }
}
开发者ID:milkiwayRN,项目名称:summator_cdma,代码行数:34,代码来源:myserver.cpp


示例13: debug_printf

//---------------------------------------------------------------------------
void
DagmanClassad::Update( int total, int done, int pre, int submitted,
			int post, int ready, int failed, int unready,
			Dag::dag_status dagStatus, bool recovery, const DagmanStats &stats )
{

	if ( !_valid ) {
		debug_printf( DEBUG_VERBOSE,
					"Skipping ClassAd update -- DagmanClassad object is invalid\n" );
		return;
	}

	Qmgr_connection *queue = OpenConnection();
	if ( !queue ) {
		return;
	}

	SetDagAttribute( ATTR_DAG_NODES_TOTAL, total );
	SetDagAttribute( ATTR_DAG_NODES_DONE, done );
	SetDagAttribute( ATTR_DAG_NODES_PRERUN, pre );
	SetDagAttribute( ATTR_DAG_NODES_QUEUED, submitted );
	SetDagAttribute( ATTR_DAG_NODES_POSTRUN, post );
	SetDagAttribute( ATTR_DAG_NODES_READY, ready );
	SetDagAttribute( ATTR_DAG_NODES_FAILED, failed );
	SetDagAttribute( ATTR_DAG_NODES_UNREADY, unready );
	SetDagAttribute( ATTR_DAG_STATUS, (int)dagStatus );
	SetDagAttribute( ATTR_DAG_IN_RECOVERY, recovery );
	
	// Publish DAGMan stats to a classad, then update those also
	ClassAd stats_ad;
	stats.Publish( stats_ad );
	SetDagAttribute( ATTR_DAG_STATS, stats_ad );

	CloseConnection( queue );
}
开发者ID:bbockelm,项目名称:htcondor,代码行数:36,代码来源:dagman_classad.cpp


示例14: CONS_Printf

const char *GetMODVersion(void)
{
	static msg_t msg;


	// we must be connected to the master server before writing to it
	if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0))
	{
		CONS_Printf("cannot connect to the master server\n");
		M_StartMessage("There was a problem connecting to\nthe Master Server", NULL, MM_NOTHING);
		return NULL;
	}

	msg.type = GET_VERSION_MSG;
	msg.length = sizeof MODVERSION;
	msg.room = MODID; // Might as well use it for something.
	sprintf(msg.buffer,"%d",MODVERSION);
	if (MS_Write(&msg) < 0)
		return NULL;

	MS_Read(&msg);
	CloseConnection();

	if(strcmp(msg.buffer,"NULL") != 0)
	{
		return msg.buffer;
	}
	else
		return NULL;
}
开发者ID:Pupswoof117,项目名称:SRB2-Public,代码行数:30,代码来源:mserv.c


示例15: OpenConnection

void InputImpl::setMousePosition(const Vector2i& position)
{
    // Open a connection with the X server
    xcb_connection_t* connection = OpenConnection();

    ScopedXcbPtr<xcb_generic_error_t> error(xcb_request_check(
            connection,
            xcb_warp_pointer(
                connection,
                None,                             // Source window
                XCBDefaultRootWindow(connection), // Destination window
                0, 0,                             // Source position
                0, 0,                             // Source size
                position.x, position.y            // Destination position
            )
                                            ));

    if (error)
        err() << "Failed to set mouse position" << std::endl;

    xcb_flush(connection);

    // Close the connection with the X server
    CloseConnection(connection);
}
开发者ID:Chaosus,项目名称:SFML,代码行数:25,代码来源:InputImpl.cpp


示例16: CloseAllConnections

 void CloseAllConnections(std::vector<SocketServer::Connection*>& clients) {
   for(std::vector<SocketServer::Connection*>::iterator it = clients.begin(); it != clients.end(); ++it ) {
     CloseConnection(*it);
     delete *it;
   }
   clients.clear();
 }
开发者ID:APTriTec,项目名称:libjson-rpc-cpp,代码行数:7,代码来源:socketserver.cpp


示例17: CloseConnection

void CloseConnection(int handle)
{
    char buf[512];
    int j;

    FD_CLR(handle, &status);

    if (connections[handle]->name[0])
    {
        sprintf(buf, "* Disconnected: %s\r\n", connections[handle]->name);

        for (j = 0; j < FD_SETSIZE; j++)
        {
            if (handle != j && j != tsocket && FD_ISSET(j, &status))
            {
                if (write(j, buf, strlen(buf)) < 0)
                {
                    CloseConnection(j);
                }
            }
        }
    } else
    {
        printf ("-- Connection %d disconnected\n", handle);
    }
    if (connections[handle])
    {
        free(connections[handle]);
    }
    close(handle);
}
开发者ID:Anatolt,项目名称:RosettaCodeData,代码行数:31,代码来源:chat-server.c


示例18: MainQuit

void MainQuit(HWND hwnd)
{
	CloseConnection();
	
	if (config.save_settings)
		SaveSettings();
	FreeProfaneTerms();
	
	MainExitState();
	
	FontsDestroy();
	ColorsDestroy();
	MusicClose();
	PaletteDeactivate();
	
	DeleteObject(hPal);

	HookClose();
	
	FreeLibrary(hRichEditLib);

	D3DRenderShutDown();
	
	PostQuitMessage(0);
}
开发者ID:jboullion,项目名称:Meridian59,代码行数:25,代码来源:winmsg.c


示例19: ConnectionFailed

static INT32 ConnectionFailed(void)
{
	con_state = MSCS_FAILED;
	CONS_Printf("Connection to master server failed\n");
	CloseConnection();
	return MS_CONNECT_ERROR;
}
开发者ID:Pupswoof117,项目名称:SRB2-Public,代码行数:7,代码来源:mserv.c


示例20: CallbackOnPoll

//------------------------------------------------------------------------------------------------------------------------------------------------------
err_t CallbackOnPoll(void *_arg, struct tcp_pcb *_tpcb)
{
    err_t ret_err;
    struct State *ss = (struct State *)_arg;
    if (ss != NULL)
    {
        if (ss->p != NULL)
        {
            // there is a remaining pbuf (chain)
            //tcp_sent(_tpcb, CallbackOnSent);
            Send(_tpcb, ss);
        }
        else
        {
            // no remaining pbuf (chain)
            if (ss->state == S_CLOSING)
            {
                CloseConnection(_tpcb, ss);
            }
        }
        ret_err = ERR_OK;
    }
    else
    {
        // nothing to be done
        tcp_abort(_tpcb);
        ret_err = ERR_ABRT;
    }
    return ret_err;
}
开发者ID:Sasha7b9,项目名称:Osci,代码行数:31,代码来源:TcpSocket.c



注:本文中的CloseConnection函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ CloseDB函数代码示例发布时间:2022-05-30
下一篇:
C++ CloseComponent函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap