本文整理汇总了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;
}
示例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
示例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;
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
示例8: socketClose
void UdpConnection::stop()
{
if (mIsOpen==true)
{
mIsOpen = false;
socketClose(&mSock);
}
}
示例9: socketClose
virtual ~Socket()
{
if(isConnected())
{
socketClose(sock);
sock = INVALID_SOCKET;
}
}
示例10: disconnect
void disconnect()
{
if(isConnected())
{
socketClose(sock);
sock = INVALID_SOCKET;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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 );
}