Annotation of OpenXM_contrib2/asir2000/io/tcpf_win_mini.c, Revision 1.2
1.2 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/io/tcpf_win_mini.c,v 1.1 2006/09/26 05:35:26 noro Exp $ */
1.1 noro 2:
3: #include "ca.h"
4: #include "parse.h"
5: #include "com.h"
6: #include <signal.h>
7: #include <string.h>
8: #include "ox.h"
9: #include <stdlib.h>
10: #include <winsock2.h>
11: #include <process.h>
12: static int control_port,server_port;
13: int win_ox_launch();
14: void win_spawn_server(char *control_port_str,char *server_port_str);
15: void win_get_rootdir(rootdir);
16: char *win_pop_string();
17: static int launched=0;
18: extern int terminate;
19:
20: int win_ox_launch()
21: {
22: int cs,ss,cn,sn;
23: char control_port_str[BUFSIZ];
24: char server_port_str[BUFSIZ];
25:
26: if ( launched ) return 0;
27:
28: control_port_str[0] = 0;
29: server_port_str[0] = 0;
30: do {
31: generate_port(0,control_port_str);
32: generate_port(0,server_port_str);
33: cs = try_bind_listen(0,control_port_str);
34: if ( cs < 0 ) continue;
35: ss = try_bind_listen(0,server_port_str);
36: if ( ss < 0 ) continue;
37: win_spawn_server(control_port_str,server_port_str);
38: cs = try_accept(0,cs);
39: if ( cs < 0 ) continue;
40: ss = try_accept(0,ss);
41: if ( ss < 0 ) continue;
42: } while ( cs < 0 || ss < 0 );
43:
44: /* client mode */
45: cn = get_iofp(cs,control_port_str,0);
46: sn = get_iofp(ss,server_port_str,0);
47: /* get_iofp returns -1 if the laucher could not spawn the server */
48: if ( sn < 0 ) {
49: /* we should terminate the launcher */
50: ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
51: return -1;
52: }
53:
54: /* register server to the server list */
55: control_port = cn;
56: server_port = sn;
57: launched = 1;
58: return 0;
59: }
60:
1.2 ! noro 61: void win_get_rootdir(char *dir);
! 62:
1.1 noro 63: void win_spawn_server(char *control_port_str,char *server_port_str)
64: {
65: char AsirExe[BUFSIZ];
66: char AsirExePath[BUFSIZ];
67: char rootdir[BUFSIZ];
68: char *av[BUFSIZ];
69:
1.2 ! noro 70: win_get_rootdir(rootdir);
! 71: // strcpy(rootdir,"c:\\program files\\asir");
1.1 noro 72: sprintf(AsirExe,"%s\\bin\\engine.exe",rootdir);
73: sprintf(AsirExePath,"\"%s\"",AsirExe);
74: av[0] = "ox_launch";
75: av[1] = "127.0.0.1";
76: av[2] = "0";
77: av[3] = control_port_str;
78: av[4] = server_port_str;
79: av[5] = "ox_asir_wfep";
80: av[6] = "1";
81: av[7] = AsirExePath;
82: av[8] = 0;
83:
84: _spawnv(_P_NOWAIT,AsirExe,av);
85: }
86:
1.2 ! noro 87: void win_get_rootdir(char *dir)
! 88: {
! 89: char *slash;
! 90:
! 91: GetCurrentDirectory(BUFSIZ,dir);
! 92: slash = strrchr(dir,'\\');
! 93: if ( slash ) *slash = 0;
! 94: }
! 95:
1.1 noro 96: char *win_pop_string()
97: {
98: Obj obj;
99: int id,serial;
100:
101: if ( !launched ) return "";
102: serial = ox_recv(server_port,&id,&obj);
103: if ( serial < 0 ) return 0;
104:
105: if ( id == OX_DATA ) {
106: if ( obj && OID(obj) == O_STR ) return BDY((STRING)obj);
107: else return "";
108: } else if ( id == OX_SYNC_BALL ) {
109: ox_send_sync(server_port);
110: ox_flush_stream_force(server_port);
111: return "";
112: } else return "";
113: }
114:
115: void win_execute_string(char *cmd)
116: {
117: struct oSTRING str;
118:
119: if ( !launched ) return;
120: OID(&str) = O_STR;
121: BDY(&str) = cmd;
122: ox_send_data(server_port,&str);
123: ox_send_cmd(server_port,SM_executeStringByLocalParser);
124: ox_send_cmd(server_port,SM_popString);
125: ox_flush_stream_force(server_port);
126: }
127:
128: void ox_reset()
129: {
130: USINT t;
131: int id;
132: Obj obj;
133:
134: if ( !launched ) return;
135: ox_send_cmd(control_port,SM_control_reset_connection);
136: ox_flush_stream_force(control_port);
137: ox_recv(control_port,&id,&obj); t = (USINT)obj;
138: Sleep(100);
139: ox_send_cmd(server_port,SM_nop);
140: ox_flush_stream_force(server_port);
141: }
142:
143: void ox_shutdown()
144: {
145: if ( !launched ) return;
146: terminate = 1;
147: ox_send_cmd(server_port,SM_shutdown);
148: Sleep(100);
149: ox_send_cmd(control_port,SM_shutdown);
150: }
151:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>