Annotation of OpenXM_contrib2/asir2000/io/tcpf_win_mini.c, Revision 1.1
1.1 ! noro 1: /* $OpenXM$ */
! 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:
! 61: void win_spawn_server(char *control_port_str,char *server_port_str)
! 62: {
! 63: char AsirExe[BUFSIZ];
! 64: char AsirExePath[BUFSIZ];
! 65: char rootdir[BUFSIZ];
! 66: char *av[BUFSIZ];
! 67:
! 68: // win_get_rootdir(rootdir);
! 69: strcpy(rootdir,"c:\\program files\\asir");
! 70: sprintf(AsirExe,"%s\\bin\\engine.exe",rootdir);
! 71: sprintf(AsirExePath,"\"%s\"",AsirExe);
! 72: av[0] = "ox_launch";
! 73: av[1] = "127.0.0.1";
! 74: av[2] = "0";
! 75: av[3] = control_port_str;
! 76: av[4] = server_port_str;
! 77: av[5] = "ox_asir_wfep";
! 78: av[6] = "1";
! 79: av[7] = AsirExePath;
! 80: av[8] = 0;
! 81:
! 82: _spawnv(_P_NOWAIT,AsirExe,av);
! 83: }
! 84:
! 85: char *win_pop_string()
! 86: {
! 87: Obj obj;
! 88: int id,serial;
! 89:
! 90: if ( !launched ) return "";
! 91: serial = ox_recv(server_port,&id,&obj);
! 92: if ( serial < 0 ) return 0;
! 93:
! 94: if ( id == OX_DATA ) {
! 95: if ( obj && OID(obj) == O_STR ) return BDY((STRING)obj);
! 96: else return "";
! 97: } else if ( id == OX_SYNC_BALL ) {
! 98: ox_send_sync(server_port);
! 99: ox_flush_stream_force(server_port);
! 100: return "";
! 101: } else return "";
! 102: }
! 103:
! 104: void win_execute_string(char *cmd)
! 105: {
! 106: struct oSTRING str;
! 107:
! 108: if ( !launched ) return;
! 109: OID(&str) = O_STR;
! 110: BDY(&str) = cmd;
! 111: ox_send_data(server_port,&str);
! 112: ox_send_cmd(server_port,SM_executeStringByLocalParser);
! 113: ox_send_cmd(server_port,SM_popString);
! 114: ox_flush_stream_force(server_port);
! 115: }
! 116:
! 117: void ox_reset()
! 118: {
! 119: USINT t;
! 120: int id;
! 121: Obj obj;
! 122:
! 123: if ( !launched ) return;
! 124: ox_send_cmd(control_port,SM_control_reset_connection);
! 125: ox_flush_stream_force(control_port);
! 126: ox_recv(control_port,&id,&obj); t = (USINT)obj;
! 127: Sleep(100);
! 128: ox_send_cmd(server_port,SM_nop);
! 129: ox_flush_stream_force(server_port);
! 130: }
! 131:
! 132: void ox_shutdown()
! 133: {
! 134: if ( !launched ) return;
! 135: terminate = 1;
! 136: ox_send_cmd(server_port,SM_shutdown);
! 137: Sleep(100);
! 138: ox_send_cmd(control_port,SM_shutdown);
! 139: }
! 140:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>