EVCCAuthorizationSetup::EVCCAuthorizationSetup(void* comm_session, int sockfd, int clientfd): StateEVCC(comm_session, timeouts.AUTHORIZATION_SETUP_REQ, "EVCCAuthorizationSetup"),
sock_fd(sockfd),client_fd(clientfd)
{
};
void EVCCAuthorizationSetup::process_message(void* message)
{
char buffer[1024];
try
{
std::cout << "EVCCAuthorizationSetup sockfd " << sock_fd << std::endl;
while(true)
{
if (is_data_available(sock_fd, 5000))
{
std::cout << "有数据可读" << endl;
}
else
{
std::cout << "没有数据或发生了其他错误" << endl;
}
int received_bytes = receive_data(sock_fd, buffer, sizeof(buffer));
std::cout << "Received bytes: " << received_bytes << std::endl;
if(received_bytes > 0)
{
std::cout << "received_bytes > 0" << std::endl;
}
else if(received_bytes == 0)
{
std::cout << "Connection closed by the other end." << std::endl;
}
else
{
std::cerr << "Error in receiving data: " << strerror(errno) << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}catch (const std::exception& e) {
std::cerr << "Exception caught: " << e.what() << std::endl;
}
};