static int SSLNetClose(int net_hd) { int iRet; iRet = NetCloseSocket(net_hd); DebugOutput("%s--%d--%s, iRet:%d\n", __FILE__, __LINE__, __FUNCTION__, iRet);//linzhao return 0; }
NetSocket::~NetSocket() { if (m_sockfd != -1) { NetCloseSocket(m_sockfd); m_sockfd = -1; } }
void NetSocket::Close() { if (m_sockfd != -1) { NetCloseSocket(m_sockfd); m_sockfd = -1; } }
void NetSocketListener::StopListening() { m_listening = false; m_binding = false; NetSleep(250); if (int(m_sockfd) >= 0) { shutdown(m_sockfd, 0); } NetCloseSocket(m_sockfd); }
int GprsRestart(void) { GprsStateClear(); NetCloseSocket(hsocket); GprsSetApn(ParaTerm.svrip.apn); GprsSetUserPwd((const char *)ParaTerm.vpn.user, (const char *)ParaTerm.vpn.pwd); return 0; }
void GprsDisConnect(void) { PrintLog(LOGTYPE_DEBUG,"gprs dis connect...\n"); GprsDevLineState = GSTAT_LINE_OFF; SvrCommLineState = LINESTAT_OFF; NetCloseSocket(hsocket); #ifdef METER_MODULE Signel_led(Signel_R,1); #endif return ; }
void WifiHook() { int ret; #ifdef DEBUG_USE return; #endif ret = NetCloseSocket(wnet_socket_id); if(ret == 0) { wnet_socket_id = -1; } return; }
static int SSLNetOpen(char *remote_addr, short remote_port, short local_port, long flag) { int iErrMsg, iRet; NET_SOCKADDR stSocketAddr; if(s_iSocket>= 0) { DebugOutput("%s--%d, s_iSocket:%d\n", __FILE__, __LINE__, s_iSocket); return s_iSocket; } s_iSocket = NetSocket(NET_AF_INET, NET_SOCK_STREAM, 0); DebugOutput("%s--%d--%s, s_iSocket:%d\n", __FILE__, __LINE__, __FUNCTION__, s_iSocket);//linzhao if (s_iSocket < 0) { return s_iSocket; } SockAddrSet(&stSocketAddr, remote_addr, remote_port); iErrMsg = NetConnect(s_iSocket, &stSocketAddr, sizeof(stSocketAddr)); DebugOutput("%s--%d--%s, iErrMsg:%d\n", __FILE__, __LINE__, __FUNCTION__, iErrMsg);//linzhao if (iErrMsg < 0) { iRet = NetCloseSocket(s_iSocket); DebugOutput("%s--%d, iRet;%d, s_iSocket:%d\n", __FILE__, __LINE__, iRet, s_iSocket); //linzhao //if (0==iRet) // s_iSocket = -1; switch (iErrMsg) { case NET_ERR_TIMEOUT: return -ERR_SSL_TIMEOUT; case NET_ERR_RST: return -ERR_SSL_NET; default: return iErrMsg; } } return s_iSocket; }
int WifiStartServer(void) { int iRet; struct net_sockaddr server_addr; if(server_socket_id >= 0) { NetCloseSocket(server_socket_id); server_socket_id = -1; } iRet = NetSocket(NET_AF_INET, NET_SOCK_STREAM, 0); if(iRet < 0) { return iRet; } server_socket_id = iRet; iRet = SockAddrSet(&server_addr, glSysCtrl.szLocalIp, (short)atoi(glSysCtrl.szLocalPort)); if(iRet < 0) { return iRet; } iRet = NetBind(server_socket_id, &server_addr, sizeof(server_addr)); if(iRet < 0) { return iRet; } iRet = NetListen(server_socket_id, 5); if(glSysCtrl.bDebugOpt) { DebugOutput("listen start = [%d]", iRet); } return iRet; }
int wifiConnect(uchar *inIp, uchar *inPort) { int i = 0; int ret; int trans_port; int event; int ret_num; char sBuff[33]; ST_WIFI_AP WifiAp; struct net_sockaddr server_addr; for (i = 0;i < 1; i++) // change 5 to 1 by wuc 2014.9.2 { ret = WifiCheck(&WifiAp); if (ret < 0) { ret = WifiApLogin(); if (ret != 0 && i != 4) { continue; } else if (ret != 0 && i == 4) { return ret; } else { break; } } else if (ret == 0) { DelayMs(500); continue; } else { break; } } trans_port = atoi(inPort); //如果TCP仍然连接,就不用再连接 if(wnet_socket_id >= 0) { event = Netioctl(wnet_socket_id, CMD_EVENT_GET, 0); if(event&(SOCK_EVENT_CONN|SOCK_EVENT_WRITE|SOCK_EVENT_READ)) { return 0; } } if(wnet_socket_id >= 0) { NetCloseSocket(wnet_socket_id); wnet_socket_id = -1; } ret = NetSocket(NET_AF_INET, NET_SOCK_STREAM, 0); if(ret < 0) { return -1; } wnet_socket_id = ret; /*ret = Netioctl(wnet_socket_id, CMD_TO_SET, 30*1000);//advice from S/W department if (ret != 0) { DebugOutput("ret = [%d]", ret); return ret; }*/ SockAddrSet(&server_addr, (char*)inIp, (short)trans_port); ret_num = NetConnect(wnet_socket_id, &server_addr, sizeof(server_addr)); if(ret_num < 0) { switch (ret_num) { case NET_ERR_ABRT: case NET_ERR_CONN: case NET_ERR_IF://linzhao strcpy(sBuff,_T("CONN FAIL")); break; case NET_ERR_RST: strcpy(sBuff,_T("CONN RESET")); break; case NET_ERR_CLSD: strcpy(sBuff,_T("CONN CLOSE")); break; case NET_ERR_RTE: strcpy(sBuff,_T("ROUTE ERR")); break; case NET_ERR_ISCONN: strcpy(sBuff,_T("CONN EXIST")); break; case NET_ERR_TIMEOUT: strcpy(sBuff,_T("CONN TIMOUT")); break; case NET_ERR_PASSWD: strcpy(sBuff,_T("PASSWORD ERR")); break; case NET_ERR_MODEM: strcpy(sBuff,_T("PPP FAIL")); break; case NET_ERR_LINKDOWN: case NET_ERR_LOGOUT: case NET_ERR_PPP: strcpy(sBuff,_T("RETRY PPP")); break; default: strcpy(sBuff,_T("UNKNOW ERR")); break; } ScrClrBelow(2); PubDispString(sBuff, DISP_LINE_LEFT|2); //Cielo要求去除返回码, linzhao // sprintf(sBuff, _T("code=%d "), ret_num); // PubDispString(sBuff, DISP_LINE_LEFT|3); PubWaitKey(2); NetCloseSocket(wnet_socket_id); wnet_socket_id = -1; return -1; } else return 0; }
NetSocketListener::~NetSocketListener() { NetCloseSocket(m_sockfd); }