C_File::~C_File()
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	if( (_bIs32s && iFile != -1) || (!_bIs32s && hFile != INVALID_HANDLE_VALUE) ){
		Close();
	}
	ListOut();
};
Exemple #2
0
/*------------------------------------------------------------------------------------------------------------------
-- FUNCTION:	menuAction
--
-- DATE:		January 14, 2016
--
-- REVISIONS:	Feb 5, 2016			- change menu value and connect others
--
-- DESIGNER:	Eunwon Moon
--
-- PROGRAMMER:	Eunwon Moon
--
-- INTERFACE: BOOL menuAction(HWND hwnd, WPARAM wParam)
--					HWND hwnd     : a handle to the window procedure which received the message.
--					WPARAM wParam : tha additional message information 
--
-- RETURNS: bool
--
--
-- NOTES:
-- This function is used to read command message and perform the menu action in dialog item
--
----------------------------------------------------------------------------------------------------------------------*/
void menuAction(HWND hwnd, WPARAM wParam)
{
	TCHAR str_port[STRSIZE], str[STRSIZE], str2[STRSIZE], str_addr[STRSIZE], str_file[STRSIZE];
	char temp[STRSIZE] = "";
	int check = 0;
	int packet_size, trial_num, port_num = DEFAULTPORT;
	
	WCHAR szFileName[STRSIZE];


	switch (LOWORD(wParam)) {

		case IDC_RADIO_SERVER:
			op_type = SERVER;
			ListOut("SERVER");
			changeType(hwnd, op_type % 2);
			break;
		case IDC_RADIO_CLIENT:
			op_type = CLIENT;
			ListOut("CLIENT");
			changeType(hwnd, op_type % 2);
			break;

		case IDC_RADIO_TCP:
			op_protocol = TCP;
			ListOut("TCP");
			return ;

		case IDC_RADIO_UDP:
			op_protocol = UDP;
			ListOut("UDP");
			return ;

		case IDC_BTN_FILE:
			GetDlgItemText(hwnd, IDC_EDIT_FILE, str_file, STRSIZE);
			if (strcmp(str_file, "") == 0)
			{
				ListOut("Input File Name!!");
				return;
			}
			op_msg = FILESEND;

		case IDC_BTN_CONN:
			EnableWindow(GetDlgItem(hwnd, IDC_RADIO_SERVER), FALSE);
			EnableWindow(GetDlgItem(hwnd, IDC_RADIO_CLIENT), FALSE);

			GetDlgItemText(hwnd, IDC_EDIT_PORT, str_port, STRSIZE);
			if (!isdigit(*str_port) && strcmp(str_port, "") != 0) {
				MessageBox(NULL, TEXT("Please Input valid port number"), NULL, MB_OK);
				break;
			}
			else if (strcmp(str_port, "") != 0)
				port_num = atoi(str_port);
			else
				port_num = DEFAULTPORT;

			if (op_type == CLIENT) {
				GetDlgItemText(hwnd, IDC_EDIT_ADDR, str_addr, STRSIZE);
				GetDlgItemText(hwnd, IDC_EDIT_SIZE, str, STRSIZE);
				GetDlgItemText(hwnd, IDC_EDIT_NUM, str2, STRSIZE);
				if (strcmp(str, "") == 0 || (op_msg !=FILESEND && strcmp(str2, "") == 0)) {
					SendMessage(hList, LB_RESETCONTENT, 0, 0);
					ListOut("Please input the value");
					break;
				}
				else if (!isdigit(*str) && !isdigit(*str2)) {
					SendMessage(hList, LB_RESETCONTENT, 0, 0);
					ListOut("Please input the valid address");
					break;
				}
				else {
					wsprintf(temp, "START CLIENT IP : %s, PORT: %d", str_addr, port_num);
					ListOut(temp);
					packet_size = atoi(str);
					trial_num = atoi(str2);
				}
				cl_winsock(hwnd, &client_sock, op_protocol, str_addr, port_num, op_msg);
			}
			else if (op_type == SERVER) {
				wsprintf(temp, "START SERVER PORT: %d", port_num);
				ListOut(temp);
				sv_winsock(hwnd, &server_sock, op_protocol, port_num);
			}
			else {
				ListOut("Sth wrong");
				ListOut(" ");
			}
			break;

		case IDCLEAR:
			SendMessage(hList, LB_RESETCONTENT, 0, 0);
			break;

		case IDDISCONNECT:
			ListOut(" disconnected!");

			shutdown(op_type == SERVER ? server_sock : client_sock, SD_BOTH);
			closesocket(op_type == CLIENT ? server_sock : client_sock);
		
			WSACleanup();
			EnableWindow(GetDlgItem(hwnd, IDC_RADIO_SERVER), TRUE);
			EnableWindow(GetDlgItem(hwnd, IDC_RADIO_CLIENT), TRUE);
			break;
		case IDCLOSE:
			PostQuitMessage(0);
			return;
	}


}