本文整理汇总了C++中socketClose函数的典型用法代码示例。如果您正苦于以下问题:C++ socketClose函数的具体用法?C++ socketClose怎么用?C++ socketClose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了socketClose函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: socketConnect
uint32_t REDFLY::gettime(uint8_t *server, uint16_t port)
{
uint8_t buf[64]; //min. NTP_PACKETLEN
uint32_t time=0UL, timeout;
uint8_t hNTP, sock, buf_len, *ptr;
uint16_t rd, len;
if(port == 0)
{
port = NTP_PORT;
}
//open connection to server
hNTP = socketConnect(PROTO_UDP, server, port, port);
if(hNTP != INVALID_SOCKET)
{
//send NTP request
memset(buf, 0, NTP_PACKETLEN);
buf[NTP_FLAGOFFSET] = (0<<6)|(1<<3)|(3<<0); //NTP flags: LI=0 | VN=1 | Mode=3 -> Client
if(socketSend(hNTP, buf, NTP_PACKETLEN) == 0)
{
//get data
ptr = buf;
buf_len = 0;
for(timeout=F_CPU/16UL; timeout!=0; timeout--) //about 3s
{
sock = hNTP;
rd = socketRead(&sock, &len, ptr, sizeof(buf)-buf_len);
if((rd != 0) && (rd != 0xFFFF)) //0xFFFF = connection closed
{
ptr += rd;
buf_len += rd;
}
if(buf_len && (len == 0)) //all data received?
{
break;
}
}
//check data
if((buf_len >= NTP_PACKETLEN) && ((buf[NTP_FLAGOFFSET]&0x07) == 4)) //NTP flags: Mode=4 -> Server
{
//time = (uint32_t)*((uint32_t*)&buf[NTP_TIMEOFFSET]);
time = (((uint32_t)buf[NTP_TIMEOFFSET+0])<<24)|
(((uint32_t)buf[NTP_TIMEOFFSET+1])<<16)|
(((uint32_t)buf[NTP_TIMEOFFSET+2])<< 8)|
(((uint32_t)buf[NTP_TIMEOFFSET+3])<< 0); //swap32
time -= 2208988800UL; //sub seconds 1900-1970
}
}
socketClose(hNTP);
}
return time;
}
开发者ID:CMon,项目名称:arduinoWifiRemote,代码行数:54,代码来源:RedFly.cpp
示例17: socketRead
int socketRead(int * sock, void * buffer, int len) {
if (*sock < 0) {
return 0;
}
int r = recv(*sock, buffer, len, 0);
if (r < 0) {
switch (errno) {
case EWOULDBLOCK: return 0;
break;
default:
bb_log(LOG_WARNING, "Could not read data! Error: %s\n", strerror(errno));
socketClose(sock);
return 0;
break;
}
}
if (r == 0) {
socketClose(sock);
}
return r;
}//socketRead
开发者ID:Samsagax,项目名称:bumblebeed,代码行数:21,代码来源:bbsocket.c
示例18: terminadoPlanDeNiveles
void terminadoPlanDeNiveles(t_personaje *personaje) {
log_debug(logger, "Terminado plan de niveles.");
t_mensaje *mensaje = mensaje_create(TERMINADO_NIVELES,"");
int socket = socketCreate(handleConnectionError);
socketConnect(socket, personaje->orquestador->ip, personaje->orquestador->puerto, handleConnectionError);
socketSend(socket, mensaje, handleConnectionError);
free(mensaje);
socketClose(socket, NULL);
}
开发者ID:ClaraAllende,项目名称:sisop-sonicTheHedgehog,代码行数:12,代码来源:terminarNivel.c
示例19: tcpEchoStart
error_t tcpEchoStart(void)
{
error_t error;
Socket *socket;
OsTask *task;
//Debug message
TRACE_INFO("Starting TCP echo service...\r\n");
//Open a TCP socket
socket = socketOpen(SOCKET_TYPE_STREAM, SOCKET_PROTOCOL_TCP);
//Failed to open socket?
if(!socket) return ERROR_OPEN_FAILED;
//Start of exception handling block
do
{
//Bind the newly created socket to port 7
error = socketBind(socket, &IP_ADDR_ANY, ECHO_PORT);
//Failed to bind the socket to the desired port?
if(error) break;
//Place the socket into listening mode
error = socketListen(socket);
//Any error to report?
if(error) break;
//Create a task to handle incoming connection requests
task = osTaskCreate("TCP Echo Listener", tcpEchoListenerTask,
socket, 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(socket);
}
//Return status code
return error;
}
开发者ID:FXRer,项目名称:STM32F4_DISCOVERY,代码行数:52,代码来源:echo.c
示例20: socketServer
int socketServer(char * address, int nonblock) {
//delete the file currently there, if any
unlink(address);
//create the socket
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
bb_log(LOG_ERR, "Could not create socket! Error: %s\n", strerror(errno));
return -1;
}
//set to nonblocking if requested
if (nonblock == 1) {
int flags = fcntl(sock, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(sock, F_SETFL, flags);
}
//fill address information
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
// XXX this path is 107 bytes (excl. null) on Linux, a larger path is
// truncated. bb_config.socket_path can therefore be shrinked as well
strncpy(addr.sun_path, address, sizeof(addr.sun_path) - 1);
addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
//bind the socket
int ret = bind(sock, (struct sockaddr*) & addr, sizeof (addr));
if (ret == 0) {
ret = listen(sock, 100); //start listening, backlog of 100 allowed
//allow reading and writing for group and self
chmod(address, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (ret != 0) {
bb_log(LOG_ERR, "Listen failed! Error: %s\n", strerror(errno));
socketClose(&sock);
}
} else {
bb_log(LOG_ERR, "Binding failed! Error: %s\n", strerror(errno));
socketClose(&sock);
}
return sock;
}//socketServer
开发者ID:Samsagax,项目名称:bumblebeed,代码行数:38,代码来源:bbsocket.c
注:本文中的socketClose函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论