当前位置: 首页>>代码示例>>C++>>正文


C++ socketClose函数代码示例

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


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

示例1: setDomainSocketPath

int CSocketClient::start(int nSocketType, const char* cszAddr, short nPort,
		int nStyle)
{
	if (AF_UNIX == nSocketType)
	{
		setDomainSocketPath(cszAddr);
	}
	else if (AF_INET == nSocketType)
	{
		if (-1 == setInetSocket(cszAddr, nPort))
		{
			_DBG("set INET socket address & port fail");
			return -1;
		}
	}

	if (-1 != createSocket(nSocketType, nStyle))
	{
		if (SOCK_STREAM == nStyle)
		{
			if (-1 == connectServer())
			{
				socketClose();
				return -1;
			}
		}

		_DBG("[Socket Client] Socket connect success");
		return getSocketfd();
	}

	return -1;
}
开发者ID:jugo8633,项目名称:ControllerSystem,代码行数:33,代码来源:CSocketClient.cpp

示例2: socketConnect

int socketConnect(char * address, int nonblock) {
  //create the socket itself
  int sock = socket(PF_UNIX, SOCK_STREAM, 0);
  if (sock < 0) {
    bb_log(LOG_ERR, "Could not create socket. Error: %s\n", strerror(errno));
    return -1;
  }
  //full our the address information for the connection
  struct sockaddr_un addr;
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, address);
  //attempt to connect
  int r = connect(sock, (struct sockaddr*) & addr, sizeof (addr));
  if (r == 0) {
    //connection success, set nonblocking if requested.
    if (nonblock == 1) {
      int flags = fcntl(sock, F_GETFL, 0);
      flags |= O_NONBLOCK;
      fcntl(sock, F_SETFL, flags);
    }
  } else {
    //connection fail
    bb_log(LOG_ERR, "Could not connect to %s! Error: %s\n", address, strerror(errno));
    //close the socket and set it to -1
    socketClose(&sock);
  }
  return sock;
}//socketConnect
开发者ID:Samsagax,项目名称:bumblebeed,代码行数:28,代码来源:bbsocket.c

示例3: ftpCloseFile

error_t ftpCloseFile(FtpClientContext *context)
{
   error_t error;
   uint_t replyCode;

   //Invalid context?
   if(context == NULL)
      return ERROR_INVALID_PARAMETER;

   //Graceful shutdown
   socketShutdown(context->dataSocket, SOCKET_SD_BOTH);

   //Close the data socket
   socketClose(context->dataSocket);
   context->dataSocket = NULL;

   //Check the transfer status
   error = ftpSendCommand(context, NULL, &replyCode);
   //Any error to report?
   if(error) return error;

   //Check FTP response code
   if(!FTP_REPLY_CODE_2YZ(replyCode))
      return ERROR_UNEXPECTED_RESPONSE;

   //Successful processing
   return NO_ERROR;
}
开发者ID:Velleman,项目名称:VM204-Firmware,代码行数:28,代码来源:ftp_client.c

示例4: PLOG

/*
 * Class:     javm_nativeimp_NsDatagramSocketImpl
 * Method:    datagramSocketClose
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_agentj_nativeimp_NsDatagramSocketImpl_datagramSocketClose
(JNIEnv *env, jobject javaobj) {
    PLOG(PL_DEBUG, "NsDatagramSocketImpl_datagramSocketClose: entering...\n");
    socketClose(env,javaobj);

    PLOG(PL_DEBUG, "NsDatagramSocketImpl_datagramSocketClose: exiting...\n");
}
开发者ID:Nhuongld,项目名称:nsj,代码行数:12,代码来源:JAVMDatagramSocket.cpp

示例5: udpEchoStart

error_t udpEchoStart(void)
{
   error_t error;
   EchoServiceContext *context;
   OsTask *task;

   //Debug message
   TRACE_INFO("Starting UDP echo service...\r\n");

   //Allocate a memory block to hold the context
   context = osMemAlloc(sizeof(EchoServiceContext));
   //Failed to allocate memory?
   if(!context) return ERROR_OUT_OF_MEMORY;

   //Start of exception handling block
   do
   {
      //Open a UDP socket
      context->socket = socketOpen(SOCKET_TYPE_DGRAM, SOCKET_PROTOCOL_UDP);

      //Failed to open socket?
      if(!context->socket)
      {
         //Report an error
         error = ERROR_OPEN_FAILED;
         //Exit immediately
         break;
      }

      //The server listens for incoming datagrams on port 7
      error = socketBind(context->socket, &IP_ADDR_ANY, ECHO_PORT);
      //Unable to bind the socket to the desired port?
      if(error) break;

      //Create a task to handle incoming datagrams
      task = osTaskCreate("UDP Echo", udpEchoTask,
         context, ECHO_SERVICE_STACK_SIZE, ECHO_SERVICE_PRIORITY);

      //Unable to create the task?
      if(task == OS_INVALID_HANDLE)
      {
         //Report an error to the calling function
         error = ERROR_OUT_OF_RESOURCES;
         break;
      }

      //End of exception handling block
   } while(0);

   //Any error to report?
   if(error)
   {
      //Clean up side effects...
      socketClose(context->socket);
      osMemFree(context);
   }

   //Return status code
   return error;
}
开发者ID:FXRer,项目名称:STM32F4_DISCOVERY,代码行数:60,代码来源:echo.c

示例6: openavbEptClntSendToServer

static bool openavbEptClntSendToServer(int h, openavbEndpointMessage_t *msg)
{
	AVB_TRACE_ENTRY(AVB_TRACE_ENDPOINT);

	if (!msg || h == AVB_ENDPOINT_HANDLE_INVALID) {
		AVB_LOG_ERROR("Client send: invalid argument passed");
		AVB_TRACE_EXIT(AVB_TRACE_ENDPOINT);
		return FALSE;
	}

	ssize_t nWrite = write(h, msg, OPENAVB_ENDPOINT_MSG_LEN);
	AVB_LOGF_VERBOSE("Sent message, len=%zu, nWrite=%zu", OPENAVB_ENDPOINT_MSG_LEN, nWrite);

	if (nWrite < OPENAVB_ENDPOINT_MSG_LEN) {
		if (nWrite < 0) {
			AVB_LOGF_ERROR("Client failed to write socket: %s", strerror(errno));
		}
		else if (nWrite == 0) {
			AVB_LOG_ERROR("Client send: socket closed unexpectedly");
		}
		else {
			AVB_LOG_ERROR("Client send: short write");
		}
		socketClose(h);
		AVB_TRACE_EXIT(AVB_TRACE_ENDPOINT);
		return FALSE;
	}

	AVB_TRACE_EXIT(AVB_TRACE_ENDPOINT);
	return TRUE;
}
开发者ID:AVnu,项目名称:Open-AVB,代码行数:31,代码来源:openavb_endpoint_client_osal.c

示例7: openavbEptClntOpenSrvrConnection

int openavbEptClntOpenSrvrConnection(tl_state_t *pTLState)
{
	AVB_TRACE_ENTRY(AVB_TRACE_ENDPOINT);
	struct sockaddr_un server;
	server.sun_family = AF_UNIX;
	snprintf(server.sun_path, UNIX_PATH_MAX, AVB_ENDPOINT_UNIX_PATH);

	int h = socket(AF_UNIX, SOCK_STREAM, 0);
	if (h < 0) {
		AVB_LOGF_DEBUG("Failed to open socket: %s", strerror(errno));
		AVB_TRACE_EXIT(AVB_TRACE_ENDPOINT);
		return AVB_ENDPOINT_HANDLE_INVALID;
	}

	AVB_LOGF_DEBUG("Connecting to %s", server.sun_path);
	int rslt = connect(h, (struct sockaddr*)&server, sizeof(struct sockaddr_un));
	if (rslt < 0) {
		AVB_LOGF_DEBUG("Failed to connect socket: %s", strerror(errno));
		socketClose(h);
		AVB_TRACE_EXIT(AVB_TRACE_ENDPOINT);
		return AVB_ENDPOINT_HANDLE_INVALID;
	}

	AVB_LOG_DEBUG("Connected to endpoint");
	AVB_TRACE_EXIT(AVB_TRACE_ENDPOINT);
	return h;
}
开发者ID:AVnu,项目名称:Open-AVB,代码行数:27,代码来源:openavb_endpoint_client_osal.c

示例8: socketClose

void UdpConnection::stop()
{
    if (mIsOpen==true)
    {
        mIsOpen = false;
        socketClose(&mSock);
    }
}
开发者ID:batitous,项目名称:babcode,代码行数:8,代码来源:udpconnection.cpp

示例9: socketClose

	virtual ~Socket()
	{
		if(isConnected())
		{
			socketClose(sock);
			sock = INVALID_SOCKET;
		}
	}
开发者ID:sleeplessinc,项目名称:sleepylib,代码行数:8,代码来源:socket.cpp

示例10: disconnect

	void disconnect()
	{
		if(isConnected())
		{
			socketClose(sock);
			sock = INVALID_SOCKET;
		}
	}
开发者ID:sleeplessinc,项目名称:sleepylib,代码行数:8,代码来源:socket.cpp

示例11: main

int main( int argc, char** argv )
{
    /*
     *	Initialize the memory allocator. Allow use of malloc and start
     *	with a 60K heap.  For each page request approx 8KB is allocated.
     *	60KB allows for several concurrent page requests.  If more space
     *	is required, malloc will be used for the overflow.
     */
    bopen( NULL, ( 60 * 1024 ), B_USE_MALLOC );
    signal( SIGPIPE, SIG_IGN );

    /*
     *	Initialize the web server
     */
    if ( initWebs() < 0 )
    {
        return -1;
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLOpen();
#endif

    /*
     *	Basic event loop. SocketReady returns true when a socket is ready for
     *	service. SocketSelect will block until an event occurs. SocketProcess
     *	will actually do the servicing.
     */
    while ( !finished )
    {
        if ( socketReady( -1 ) || socketSelect( -1, 1000 ) )
        {
            socketProcess( -1 );
        }

        websCgiCleanup();
        emfSchedProcess();
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLClose();
#endif
#ifdef USER_MANAGEMENT_SUPPORT
    umClose();
#endif
    /*
     *	Close the socket module, report memory leaks and close the memory allocator
     */
    websCloseServer();
    socketClose();
#ifdef B_STATS
    memLeaks();
#endif
    bclose();
    return 0;
}
开发者ID:codywon,项目名称:bell-jpg,代码行数:56,代码来源:main.c

示例12: TEST

TEST(SocketWaiter, waitOnWriteEvent) {
    ScopedPtr<SocketWaiter> waiter(SocketWaiter::create());

    int s1, s2;

    ASSERT_EQ(0, socketCreatePair(&s1, &s2));

    waiter->update(s2, SocketWaiter::kEventWrite);
    int ret = waiter->wait(0);
    EXPECT_EQ(1, ret);
    unsigned events = 0;
    EXPECT_EQ(s2, waiter->nextPendingFd(&events));
    EXPECT_EQ(SocketWaiter::kEventWrite, events);

    EXPECT_EQ(-1, waiter->nextPendingFd(&events));

    socketClose(s2);
    socketClose(s1);
}
开发者ID:Acidburn0zzz,项目名称:platform_external_qemu,代码行数:19,代码来源:SocketWaiter_unittest.cpp

示例13: dhcpv6RelayStop

error_t dhcpv6RelayStop(Dhcpv6RelayCtx *context)
{
   uint_t i;

   //Debug message
   TRACE_INFO("Stopping DHCPv6 relay agent...\r\n");

   //Ensure the specified pointer is valid
   if(!context)
      return ERROR_INVALID_PARAMETER;
   //Check DHCPv6 relay agent state
   if(!context->running)
      return ERROR_WRONG_STATE;

   //Reset ACK event before sending the kill signal
   osEventReset(context->ackEvent);
   //Stop the DHCPv6 relay agent task
   context->stopRequest = TRUE;
   //Send a signal to the task in order to abort any blocking operation
   osEventSet(context->event);

   //Wait for the process to terminate...
   osEventWait(context->ackEvent, INFINITE_DELAY);

   //Leave the All_DHCP_Relay_Agents_and_Servers multicast group
   //for each client-facing interface
   dhcpv6RelayLeaveMulticastGroup(context);

   //Close the socket that carries traffic towards the DHCPv6 server
   socketClose(context->serverSocket);

   //Properly dispose the sockets that carry traffic towards the DHCPv6 clients
   for(i = 0; i < context->clientInterfaceCount; i++)
      socketClose(context->clientSocket[i]);

   //Close event objects
   osEventClose(context->event);
   osEventClose(context->ackEvent);

   //Successful processing
   return NO_ERROR;
}
开发者ID:rpc-fw,项目名称:analyzer,代码行数:42,代码来源:dhcpv6_relay.c

示例14: socketClose

void CSocketServer::closeClient(int nClientFD)
{
	socketClose(nClientFD);
	if(mapClientThread.end() != mapClientThread.find(nClientFD))
	{
		pthread_t pid = mapClientThread[nClientFD];
		mapClientThread.erase(nClientFD);
		threadHandler->threadCancel(pid);
		sendMessage(m_nInternalFilter, EVENT_COMMAND_THREAD_EXIT, pid, 0, NULL);
	}
}
开发者ID:ideasiii,项目名称:ControllerPlatform,代码行数:11,代码来源:CSocketServer.cpp

示例15: rtems_httpd_daemon

static void
rtems_httpd_daemon(rtems_task_argument args)
{
/*
 *	Initialize the memory allocator. Allow use of malloc and start with a 
 *	10K heap.
 */
	bopen(NULL, (10 * 1024), B_USE_MALLOC);

/*
 *	Initialize the web server
 */
	if (initWebs() < 0) {
	  rtems_panic("Unable to initialize Web server !!\n");
	}

#ifdef WEBS_SSL_SUPPORT
	websSSLOpen();
#endif

/*
 *	Basic event loop. SocketReady returns true when a socket is ready for
 *	service. SocketSelect will block until an event occurs. SocketProcess
 *	will actually do the servicing.
 */
	while (!finished) {
	  if (socketReady(-1) || socketSelect(-1, 2000)) {
			socketProcess(-1);
	  }
	  /*websCgiCleanup();*/
	  emfSchedProcess();
	}

#ifdef WEBS_SSL_SUPPORT
	websSSLClose();
#endif

#ifdef USER_MANAGEMENT_SUPPORT
	umClose();
#endif

/*
 *	Close the socket module, report memory leaks and close the memory allocator
 */
	websCloseServer();
	websDefaultClose();
	socketClose();
	symSubClose();
#if B_STATS
	memLeaks();
#endif
	bclose();
        rtems_task_delete( RTEMS_SELF );
}
开发者ID:SayCV,项目名称:rtems-missing_cpukit,代码行数:54,代码来源:webmain.c


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