本文整理汇总了C++中SocketClose函数的典型用法代码示例。如果您正苦于以下问题:C++ SocketClose函数的具体用法?C++ SocketClose怎么用?C++ SocketClose使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SocketClose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _mPerfRunServer
static bool _mPerfRunServer(const char* listen, const struct mArguments* args, const struct PerfOpts* perfOpts) {
SocketSubsystemInit();
Socket server = SocketOpenTCP(7216, NULL);
if (SOCKET_FAILED(server)) {
SocketSubsystemDeinit();
return false;
}
if (SOCKET_FAILED(SocketListen(server, 0))) {
SocketClose(server);
SocketSubsystemDeinit();
return false;
}
_socket = SocketAccept(server, NULL);
if (perfOpts->csv) {
const char* header = "game_code,frames,duration,renderer\n";
SocketSend(_socket, header, strlen(header));
}
char path[PATH_MAX];
while (SocketRecv(_socket, path, sizeof(path)) > 0) {
char* nl = strchr(path, '\n');
if (nl == path) {
break;
}
if (nl) {
nl[0] = '\0';
}
if (!_mPerfRunCore(path, args, perfOpts)) {
break;
}
}
SocketClose(_socket);
SocketClose(server);
SocketSubsystemDeinit();
return true;
}
示例2: IP_ADDRESS
/**
Performs an HTTP POST operation to the path at the address / port specified. The actual post contents
are found read from a given buffer and the result is returned in the same buffer.
@param address The IP address of the server to post to.
@param port The port on the server you're connecting to. Usually 80 for HTTP.
@param hostname A string specifying the name of the host to connect to. When connecting to a server
that does shared hosting, this will specify who to connect with.
@param path The path on the server to post to.
@param buffer A pointer to the buffer to write from and read back into.
@param buffer_length An integer specifying the number of bytes to write.
@param buffer_size An integer specifying the actual size of the buffer.
@return status.
\par Example
\code
// we'll post a test message to www.makingthings.com/post/path
int addr = IP_ADDRESS( 72, 249, 53, 185); // makingthings.com is 72.249.53.185
int bufLength = 100;
char myBuffer[bufLength];
sprintf( myBuffer, "A test message to post" );
int result = WebClient_Post( addr, 80, "www.makingthings.com", "/post/path",
myBuffer, strlen("A test message to post"), bufLength );
\endcode
*/
int WebClient_Post( int address, int port, char* hostname, char* path, char* buffer, int buffer_length, int buffer_size )
{
char* b = WebClient_InternalBuffer;
int buffer_read = 0;
int wrote = 0;
void* s = Socket( address, port );
if ( s != NULL )
{
int send_len = snprintf( b, WEBCLIENT_INTERNAL_BUFFER_SIZE,
"POST %s HTTP/1.1\r\n%s%s%sContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n",
path,
( hostname != NULL ) ? "Host: " : "",
( hostname != NULL ) ? hostname : "",
( hostname != NULL ) ? "\r\n" : "",
buffer_length );
if ( send_len > WEBCLIENT_INTERNAL_BUFFER_SIZE )
{
SocketClose( s );
return CONTROLLER_ERROR_INSUFFICIENT_RESOURCES;
}
wrote = SocketWrite( s, b, send_len );
if ( wrote == 0 )
{
SocketClose( s );
return CONTROLLER_ERROR_WRITE_FAILED;
}
SocketWrite( s, buffer, buffer_length );
int content_length = 0;
int b_len;
while ( ( b_len = SocketReadLine( s, b, WEBCLIENT_INTERNAL_BUFFER_SIZE ) ) )
{
if ( strncmp( b, "\r\n", 2 ) == 0 )
break;
if ( strncmp( b, "Content-Length", 14 ) == 0 )
content_length = atoi( &b[ 16 ] );
}
if ( content_length > 0 && b_len > 0 )
{
char* bp = buffer;
while ( ( b_len = SocketRead( s, bp, buffer_size - buffer_read ) ) )
{
buffer_read += b_len;
bp += b_len;
if ( buffer_read >= content_length )
break;
}
}
SocketClose( s );
return buffer_read;
}
else
return CONTROLLER_ERROR_BAD_ADDRESS;
}
示例3: _FTCRespondInComingMessage
OSStatus _FTCRespondInComingMessage(int fd, HTTPHeader_t* inHeader, mico_Context_t * const inContext)
{
OSStatus err = kUnknownErr;
const char * value;
size_t valueSize;
easylink_log_trace();
switch(inHeader->statusCode){
case kStatusAccept:
easylink_log("Easylink server accepted!");
err = kNoErr;
goto exit;
break;
case kStatusOK:
easylink_log("Easylink server respond status OK!");
err = HTTPGetHeaderField( inHeader->buf, inHeader->len, "Content-Type", NULL, NULL, &value, &valueSize, NULL );
require_noerr(err, exit);
if( strnicmpx( value, valueSize, kMIMEType_JSON ) == 0 ){
easylink_log("Receive JSON config data!");
err = ConfigIncommingJsonMessage( inHeader->extraDataPtr, inContext);
SocketClose(&fd);
inContext->micoStatus.sys_state = eState_Software_Reset;
require(inContext->micoStatus.sys_state_change_sem, exit);
mico_rtos_set_semaphore(&inContext->micoStatus.sys_state_change_sem);
}else if(strnicmpx( value, valueSize, kMIMEType_MXCHIP_OTA ) == 0){
easylink_log("Receive OTA data!");
mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex);
memset(&inContext->flashContentInRam.bootTable, 0, sizeof(boot_table_t));
inContext->flashContentInRam.bootTable.length = inHeader->contentLength;
inContext->flashContentInRam.bootTable.start_address = UPDATE_START_ADDRESS;
inContext->flashContentInRam.bootTable.type = 'A';
inContext->flashContentInRam.bootTable.upgrade_type = 'U';
inContext->flashContentInRam.micoSystemConfig.easyLinkEnable = false;
MICOUpdateConfiguration(inContext);
mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex);
SocketClose(&fd);
inContext->micoStatus.sys_state = eState_Software_Reset;
require(inContext->micoStatus.sys_state_change_sem, exit);
mico_rtos_set_semaphore(&inContext->micoStatus.sys_state_change_sem);
}else{
return kUnsupportedDataErr;
}
err = kNoErr;
goto exit;
break;
default:
goto exit;
}
exit:
return err;
}
示例4: SNTPSend
/*---------------------------------------------------
send SNTP data
---------------------------------------------------*/
void SNTPSend(HWND hwndSNTP, unsigned long serveraddr)
{
struct sockaddr_in serversockaddr;
struct NTP_Packet NTP_Send;
unsigned int sntpver;
HOSTTIME ht;
// request notification of events
if(WSAAsyncSelect(m_socket, hwndSNTP, WSOCK_SELECT, FD_READ)
== SOCKET_ERROR)
{
SocketClose(hwndSNTP, "WSAAsyncSelect() failed");
PostMessage(hwndSNTP, SNTPM_ERROR, 0, 0);
return;
}
// set IP address and port
serversockaddr.sin_family = AF_INET;
serversockaddr.sin_addr.s_addr = serveraddr;
serversockaddr.sin_port = htons((unsigned short)m_port);
memset(serversockaddr.sin_zero,(int)0,sizeof(serversockaddr.sin_zero));
// init a packet
memset(&NTP_Send, 0, sizeof(struct NTP_Packet));
// NTP/SNTP version number = 4
// Mode = 3 (client)
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |LI | VN |Mode | Stratum | Poll | Precision |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
sntpver = GetMyRegLong(m_section, "SNTPVer", 4);
NTP_Send.Control_Byte = (BYTE)(((sntpver&0x7) << 3) | 3);
GetRealSystemTimeAsFileTime((FILETIME*)&ht);
// save tickcount
m_dwTickCountOnSend = timeGetTime();
HostTimeToNTPTime(&ht, &NTP_Send.transmit_timestamp);
// send a packet
if(sendto(m_socket, (const char *)&NTP_Send, sizeof(NTP_Send), 0,
(struct sockaddr *)&serversockaddr,
sizeof(serversockaddr)) == SOCKET_ERROR)
{
SocketClose(hwndSNTP, "sendto() failed");
PostMessage(hwndSNTP, SNTPM_ERROR, 0, 0);
return;
}
SetTimer(hwndSNTP, IDTIMER_MAIN, m_nTimeOut, NULL);
}
示例5: process_message
void
process_message (void)
{
int bytes, pos = 4;
long scount;
if (!SocketReadable (sock))
return;
GetSocketError (sock);
if ((bytes = DgramReceiveAny (sock, (char *) ibuffer, BUFFERSIZE)) <= 0)
{
if (errno == EAGAIN || errno == EWOULDBLOCK || bytes >= 0)
{
GetSocketError (sock);
return;
}
CQuit ("Can't receive server's message\n");
SocketClose (sock);
}
GETLONG (ibuffer, scount);
csetrrcount (scount);
while (pos + 2 < bytes)
{
int size;
GETSHORT (ibuffer + pos, size);
if (pos + size <= bytes)
{
ctable[ibuffer[pos + 2]].func ((ibuffer + pos + 3), size - 3);
}
pos += size;
}
}
示例6: OnGetHost
/*---------------------------------------------------
called when the window received WSOCK_GETHOST.
get IP address and send data.
---------------------------------------------------*/
void OnGetHost(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
struct hostent *pHostEnt;
unsigned long serveraddr;
if(g_hGetHost == NULL) return;
// success ?
if(WSAGETASYNCERROR(lParam) != 0)
{
SocketClose(hwnd, "failed to get IP address");
return;
}
// valid handle ?
if(g_hGetHost != (HANDLE)wParam) return;
// get IP address
pHostEnt = (struct hostent *)g_pGetHost;
serveraddr = *((unsigned long *)((pHostEnt->h_addr_list)[0]));
free(g_pGetHost); g_pGetHost = NULL;
g_hGetHost = NULL;
// send data
SNTPSend(hwnd, serveraddr);
}
示例7: GDBStubListen
bool GDBStubListen(struct GDBStub* stub, int port, const struct Address* bindAddress) {
if (!SOCKET_FAILED(stub->socket)) {
GDBStubShutdown(stub);
}
stub->socket = SocketOpenTCP(port, bindAddress);
if (SOCKET_FAILED(stub->socket)) {
mLOG(DEBUGGER, ERROR, "Couldn't open socket");
return false;
}
if (!SocketSetBlocking(stub->socket, false)) {
goto cleanup;
}
int err = SocketListen(stub->socket, 1);
if (err) {
goto cleanup;
}
return true;
cleanup:
mLOG(DEBUGGER, ERROR, "Couldn't listen on port");
SocketClose(stub->socket);
stub->socket = INVALID_SOCKET;
return false;
}
示例8: OnTimerSNTP
/*------------------------------------------------
called when main window received WM_TIMER
--------------------------------------------------*/
void OnTimerSNTP(HWND hwnd)
{
char msg[80];
wsprintf(msg, "timeout (%04d)", GetTickCount() - m_dwTickCountOnSend);
SocketClose(hwnd, msg);
PostMessage(hwnd, SNTPM_ERROR, 0, 0);
}
示例9: main
int main ()
{
int s = SocketOpen ("vcan0", 1000, 1000);
struct FrameBag bag;
int yes = 0;
gettimeofday (&t1, NULL);
gettimeofday (&t2, NULL);
while ( t2.tv_sec - t1.tv_sec < 1 )
{
if ( SocketRead (s, &bag, 1, 700) > 0
&& bag.Frame.can_id == 0x111
&& bag.Frame.can_dlc == 5
&& bag.Frame.data[0] == 1
&& bag.Frame.data[1] == 2
&& bag.Frame.data[2] == 3
&& bag.Frame.data[3] == 4
&& bag.Frame.data[4] == 5 )
{
yes = 1;
break;
}
gettimeofday (&t2, NULL);
}
SocketClose (s);
if (yes)
printf ("Тесты пройдены.\n");
else
printf ("\n ~~~ !!!!!- ^ТЕСТ ЗАВАЛЕН^ -!!!! ~~~ \n\n");
return yes ? 0 : -1;
}
示例10: GDBStubShutdown
void GDBStubShutdown(struct GDBStub* stub) {
GDBStubHangup(stub);
if (!SOCKET_FAILED(stub->socket)) {
SocketClose(stub->socket);
stub->socket = INVALID_SOCKET;
}
}
示例11: UsersDestroy
////////////////////////////////////////////////////////////
/// Destroy all users
////////////////////////////////////////////////////////////
bool UsersDestroy()
{
struct UserData * Iterator = UserList.First;
// Remove all users
while (Iterator != NULL)
{
struct UserData * TempUser = Iterator;
Iterator = Iterator->Next;
// Close the socket
MutexLock(&TempUser->MutexData);
SocketClose(&TempUser->Connection.Socket);
MutexUnlock(&TempUser->MutexData);
// Destroy the mutex
MutexDestroy(&TempUser->MutexData);
// Free it
free(TempUser);
TempUser = NULL;
}
return true;
}
示例12: SNTPSend
/*---------------------------------------------------
send SNTP data
---------------------------------------------------*/
void SNTPSend(HWND hwnd, unsigned long serveraddr)
{
struct sockaddr_in serversockaddr;
struct NTP_Packet NTP_Send;
unsigned int sntpver;
unsigned int Control_Word;
// request notification of events
if(WSAAsyncSelect(g_socket, hwnd, WSOCK_SELECT, FD_READ) == SOCKET_ERROR)
{
SocketClose(hwnd, "WSAAsyncSelect() failed");
return;
}
// set IP address and port
serversockaddr.sin_family = AF_INET;
serversockaddr.sin_addr.s_addr = serveraddr;
serversockaddr.sin_port = htons((unsigned short)g_port);
memset(serversockaddr.sin_zero,(int)0,sizeof(serversockaddr.sin_zero));
// init a packet
memset(&NTP_Send, 0, sizeof(struct NTP_Packet));
// NTP/SNTP version number = 4
// Mode = 3 (client)
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |LI | VN |Mode | Stratum | Poll | Precision |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
sntpver = GetMyRegLong("SNTP", "SNTPVer", 4);
Control_Word = (sntpver << 27) | (3 << 24);
NTP_Send.Control_Word = htonl(Control_Word);
// send a packet
if(sendto(g_socket, (const char *)&NTP_Send, sizeof(NTP_Send), 0,
(struct sockaddr *)&serversockaddr,
sizeof(serversockaddr)) == SOCKET_ERROR)
{
SocketClose(hwnd, "sendto() failed");
return;
}
// save tickcount
dwTickCountOnSend = GetTickCount();
bSendingData = TRUE;
}
示例13: quit
static void
quit (unsigned char *message, int size)
{
printf ("Uninitializing:%s\n", (char *) message);
SocketClose (sock);
quited = 1;
exit (0);
}
示例14: stopEasyLink
OSStatus stopEasyLink( mico_Context_t * const inContext)
{
(void)inContext;
micoWlanStopEasyLink();
if(easylinkClient_fd != -1)
SocketClose(&easylinkClient_fd);
return kNoErr;
}
示例15: SocketClose
void EClientSocket::eDisconnect()
{
if ( m_fd >= 0 )
// close socket
SocketClose( m_fd);
m_fd = -1;
eDisconnectBase();
}