00001 /* 00002 * (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net) 00003 * 00004 * This file is part of FREESECS. 00005 * 00006 * FREESECS is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * FREESECS is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with FREESECS, see COPYING. 00018 * If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 #include <iostream> 00021 #include <string> 00022 #include <errno.h> 00023 #include <unistd.h> 00024 #include "hsms_socket.h" 00025 #include "hsms_cnx.h" 00026 00027 typedef hsms_msg_base<hsms_socket::data_t> hsms_v_msg; 00028 typedef select_rsp<hsms_socket::data_t> hsms_v_select_rsp; 00029 00030 using namespace std; 00031 int 00032 main (int argc, char *argv[]) 00033 { 00034 /* hsms_socket sock; 00035 hsms_socket::data_t d; 00036 hsms_socket::data_t resp; 00037 00038 hsms_v_msg msg; 00039 hsms_v_select_rsp sr; 00040 00041 unsigned u; 00042 int j, i = 20; 00043 const char *st; 00044 char header[128]; 00045 00046 cout << "ceate..." << endl; 00047 if (!sock.create ()) 00048 { 00049 return -1; 00050 } 00051 cout << "bind.." << endl; 00052 if (!sock.bind (5000)) 00053 { 00054 return -1; 00055 } 00056 cout << "listen.." << endl; 00057 if (!sock.listen ()) 00058 { 00059 return -1; 00060 } 00061 cout << "accept.." << endl; 00062 if (!sock.accept ()) 00063 { 00064 return -1; 00065 } 00066 cout << "receiving loop" << endl; 00067 00068 while (--i) 00069 { 00070 d.clear (); 00071 //int status = new_hsms_socket.recv(d); 00072 int status = sock.recv (d, 1500); 00073 if(S_OK != status) 00074 { 00075 continue; 00076 } 00077 cout << "received " << d.size () << " bytes, status: " << status << endl; 00078 if (E_CNX_CLOSED == status) 00079 { 00080 cout << "cnx closed from other side" << endl; 00081 break; 00082 } 00083 cout << "Message:" << endl; 00084 for(j = 0; j < d.size(); j++) 00085 { 00086 u = d[j]; 00087 u &= 0xff; 00088 cout << u << " "; 00089 } 00090 cout << endl; 00091 00092 hsms_v_msg::msg_et et = msg.type(d); 00093 switch(et) 00094 { 00095 case hsms_v_msg::e_data: 00096 st = "data msg"; 00097 break; 00098 case hsms_v_msg::e_select_req: 00099 st = "select req"; 00100 cout << "transaction id: " << msg.transaction_id(d) << endl; 00101 sr.compose(resp, msg.transaction_id(d), hsms_v_select_rsp::e_established); 00102 cout << "Select response: " << resp.size() << endl; 00103 for(j = 0; j < resp.size(); j++) 00104 { 00105 u = resp[j]; 00106 u &= 0xff; 00107 cout << u << " "; 00108 } 00109 cout << endl; 00110 sock.send(resp); 00111 break; 00112 case hsms_v_msg::e_select_rsp: 00113 st = "select rsp"; 00114 break; 00115 case hsms_v_msg::e_deselect_req: 00116 st = "deselect req"; 00117 break; 00118 case hsms_v_msg::e_deselect_rsp: 00119 st = "deselect rsp"; 00120 break; 00121 case hsms_v_msg::e_linktest_req: 00122 st = "linktest req"; 00123 break; 00124 case hsms_v_msg::e_linktest_rsp: 00125 st = "linktest rsp"; 00126 break; 00127 case hsms_v_msg::e_reject_req: 00128 st = "reject req"; 00129 break; 00130 case hsms_v_msg::e_separate_req: 00131 st = "separate req"; 00132 break; 00133 case hsms_v_msg::e_invalid: 00134 default: 00135 st = "invalid msg type!!!"; 00136 break; 00137 } 00138 cout << "Message type: " << st << " (" << (unsigned)et << ")"<< endl; 00139 00140 d.clear(); 00141 } 00142 */ 00143 hsms_passive_cnx cnx; 00144 //hsms_active_cnx cnx; 00145 int err = cnx.start(); 00146 00147 while(1) 00148 { 00149 sleep(2); 00150 /*if(e_hsms_not_connected == cnx.status()) 00151 { 00152 break; 00153 }*/ 00154 } 00155 00156 return 0; 00157 }