📄 app_util.pc
字号:
/* * NAME: AppTcpServerListen. * PURPOSE: listen on a server port. * PARAMETERS: nodePtr - pointer to the node. * transProtocolType - which transport protocol to use. * appType - which application initiates this request. * serverAddr - server address. * serverPort - server port number. * RETURN: none. */voidAppTcpServerListen(GlomoNode *nodePtr, TRANSPORT_PROTOCOL transProtocolType, APP_TYPE appType, NODE_ADDR serverAddr, short serverPort){ AppToTcpListen *listenRequest; Message *msg; #ifdef DEBUG printf("Node %ld (TCP Server) starting to listen.\n", nodePtr->nodeAddr); #endif msg = GLOMO_MsgAlloc(nodePtr, GLOMO_TRANSPORT_LAYER, transProtocolType, MSG_TRANSPORT_FromAppListen); GLOMO_MsgInfoAlloc(nodePtr, msg, sizeof(AppToTcpListen)); listenRequest = (AppToTcpListen *) msg->info; listenRequest->appType = appType; listenRequest->localAddr = serverAddr; listenRequest->localPort = serverPort; listenRequest->priority = NON_REAL_TIME; GLOMO_MsgSend(nodePtr, msg, 0);} /* * NAME: AppTcpServerListenWithPriority. * PURPOSE: listen on a server port. * PARAMETERS: nodePtr - pointer to the node. * transProtocolType - which transport protocol to use. * appType - which application initiates this request. * serverAddr - server address. * serverPort - server port number. * priority - priority of this data for this session. * RETURN: none. */voidAppTcpServerListenWithPriority(GlomoNode *nodePtr, TRANSPORT_PROTOCOL transProtocolType, APP_TYPE appType, NODE_ADDR serverAddr, short serverPort, NetworkQueueingPriorityType priority){ AppToTcpListen *listenRequest; Message *msg; #ifdef DEBUG printf("Node %ld (TCP Server) starting to listen.\n", nodePtr->nodeAddr); #endif msg = GLOMO_MsgAlloc(nodePtr, GLOMO_TRANSPORT_LAYER, transProtocolType, MSG_TRANSPORT_FromAppListen); GLOMO_MsgInfoAlloc(nodePtr, msg, sizeof(AppToTcpListen)); listenRequest = (AppToTcpListen *) msg->info; listenRequest->appType = appType; listenRequest->localAddr = serverAddr; listenRequest->localPort = serverPort; listenRequest->priority = priority; GLOMO_MsgSend(nodePtr, msg, 0);} /* * NAME: AppTcpOpenConnection. * PURPOSE: Open a connection. * PARAMETERS: nodePtr - pointer to the node. * transProtocolType - which transport protocol to use. * appType - which application initiates this request. * remoteAddr - address of the remote node. * remotePort - port number on the remote node (server port). * uniqueId - used to determine which client is requesting * connection. * waitTime - time until the session starts. * RETURN: none. */voidAppTcpOpenConnection(GlomoNode *nodePtr, TRANSPORT_PROTOCOL transProtocolType, APP_TYPE appType, NODE_ADDR remoteAddr, short remotePort, int uniqueId, clocktype waitTime){ AppToTcpOpen *openRequest; Message *msg; #ifdef DEBUG printf("Node %ld (TCP Client) starting to open connection.\n", nodePtr->nodeAddr); #endif msg = GLOMO_MsgAlloc(nodePtr, GLOMO_TRANSPORT_LAYER, transProtocolType, MSG_TRANSPORT_FromAppOpen); GLOMO_MsgInfoAlloc(nodePtr, msg, sizeof(AppToTcpOpen)); openRequest = (AppToTcpOpen *) msg->info; openRequest->appType = appType; openRequest->localAddr = nodePtr->nodeAddr; openRequest->localPort = nodePtr->appData.nextPortNum; nodePtr->appData.nextPortNum++; openRequest->remoteAddr = remoteAddr; openRequest->remotePort = remotePort; openRequest->uniqueId = uniqueId; openRequest->priority = NON_REAL_TIME; GLOMO_MsgSend(nodePtr, msg, waitTime);}/* * NAME: AppTcpOpenConnectionWithPriority. * PURPOSE: Open a connection. * PARAMETERS: nodePtr - pointer to the node. * transProtocolType - which transport protocol to use. * appType - which application initiates this request. * remoteAddr - address of the remote node. * remotePort - port number on the remote node (server port). * uniqueId - used to determine which client is requesting * connection. * waitTime - time until the session starts. * priority - priority of the data. * RETURN: none. */voidAppTcpOpenConnectionWithPriority(GlomoNode *nodePtr, TRANSPORT_PROTOCOL transProtocolType, APP_TYPE appType, NODE_ADDR remoteAddr, short remotePort, int uniqueId, clocktype waitTime, NetworkQueueingPriorityType priority){ AppToTcpOpen *openRequest; Message *msg; #ifdef DEBUG printf("Node %ld (TCP Client) starting to open connection.\n", nodePtr->nodeAddr); #endif msg = GLOMO_MsgAlloc(nodePtr, GLOMO_TRANSPORT_LAYER, transProtocolType, MSG_TRANSPORT_FromAppOpen); GLOMO_MsgInfoAlloc(nodePtr, msg, sizeof(AppToTcpOpen)); openRequest = (AppToTcpOpen *) msg->info; openRequest->appType = appType; openRequest->localAddr = nodePtr->nodeAddr; openRequest->localPort = nodePtr->appData.nextPortNum; nodePtr->appData.nextPortNum++; openRequest->remoteAddr = remoteAddr; openRequest->remotePort = remotePort; openRequest->uniqueId = uniqueId; openRequest->priority = priority; GLOMO_MsgSend(nodePtr, msg, waitTime);}/* * NAME: AppTcpSendData. * PURPOSE: send an application data unit. * PARAMETERS: nodePtr - pointer to the node. * protocolType - which transport protocol to use. * connId - connection id. * payload - data to send. * length - length of the data to send. * RETRUN: none. */voidAppTcpSendData(GlomoNode *nodePtr, TRANSPORT_PROTOCOL protocolType, int connId, char *payload, int length){ Message *msg; AppToTcpSend *sendRequest; msg = GLOMO_MsgAlloc(nodePtr, GLOMO_TRANSPORT_LAYER, protocolType, MSG_TRANSPORT_FromAppSend); GLOMO_MsgInfoAlloc(nodePtr, msg, sizeof(AppToTcpSend)); sendRequest = (AppToTcpSend *) msg->info; sendRequest->connectionId = connId; GLOMO_MsgPacketAlloc(nodePtr, msg, length); memcpy(msg->packet, payload, length); GLOMO_MsgSend(nodePtr, msg, 0);}/* * NAME: AppTcpCloseConnection. * PURPOSE: close the connection. * PARAMETERS: nodePtr - pointer to the node. * protocolType - which transport protocol to use. * connId - connection id. * RETRUN: none. */voidAppTcpCloseConnection(GlomoNode *nodePtr, TRANSPORT_PROTOCOL protocolType, int connId) { Message *msg; AppToTcpClose *closeRequest; msg = GLOMO_MsgAlloc(nodePtr, GLOMO_TRANSPORT_LAYER, protocolType, MSG_TRANSPORT_FromAppClose); GLOMO_MsgInfoAlloc(nodePtr, msg, sizeof(AppToTcpClose)); closeRequest = (AppToTcpClose *) msg->info; closeRequest->connectionId = connId; GLOMO_MsgSend(nodePtr, msg, 0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -