• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Virtual machine Management Terminal User Interface


Commit MetaInfo

Revisión5563452411b05d582a74c603c8611cefc6d95c33 (tree)
Tiempo2022-07-02 22:36:57
AutorKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Log Message

Suppot connect(2) Non-Blocking mode.

Cambiar Resumen

Diferencia incremental

--- a/src/hvctl.c
+++ b/src/hvctl.c
@@ -432,7 +432,7 @@ int
432432
433433 // Connect ---
434434 if( HVISOR_CON_REMOTE_SSH == p_hvisor->b_connection ) {
435- i_err = SSHCmd_Connect( p_hvcon, &t_ssh );
435+ i_err = SSHCmd_Connect_Phase1( p_hvcon, &t_ssh );
436436
437437 p_hvcon->ExecCmd = SSHCmd_ExecCmd;
438438 dw_status = HVISOR_STATUS_CONNECTING;
@@ -465,29 +465,42 @@ int
465465 {
466466 int i_err = 0x00;
467467 HVisor *p_hvisor = NULL;
468+ SSH_Info t_ssh;
469+
470+ p_hvisor = HVisor_Ref( p_hvcon->i_id );
471+ if( NULL == p_hvisor ) {
472+ return -0x01;
473+ }
474+
475+ memcpy( &t_ssh, &(p_hvisor->ssh), sizeof( SSH_Info ) );
476+
477+ HVisor_Release( p_hvisor );
468478
469479 // Connect ---
470480 if( HVISOR_CON_REMOTE_SSH == p_hvcon->b_connection ) {
471- //i_err = SSHCmd_Connect( p_hvcon, &t_ssh );
481+ i_err = SSHCmd_Connect_Phase2( p_hvcon, &t_ssh );
482+ if( 0x01 == i_err ) {
483+ // Not Error -- Continue connect(2) proc. ---
484+ return 0x00;
485+ }
472486
473487 } else if( HVISOR_CON_LOCALHOST == p_hvcon->b_connection ) {
474488 // NONE Proc. ---
475489 }
476490
477491 // Set Connected flag ---
478- if( 0x00 == i_err ) {
479- p_hvisor = HVisor_Use( p_hvcon->i_id );
480- assert( NULL != p_hvisor );
492+ p_hvisor = HVisor_Use( p_hvcon->i_id );
493+ assert( NULL != p_hvisor );
481494
495+ if( 0x00 == i_err ) {
482496 p_hvcon->dw_status |= HVISOR_STATUS_CONNECTED;
483- p_hvcon->dw_status &= ~(HVISOR_STATUS_CONNECTING);
484-
485497 p_hvisor->dw_status |= HVISOR_STATUS_CONNECTED;
486- p_hvisor->dw_status &= ~(HVISOR_STATUS_CONNECTING);
498+ }
487499
488- HVisor_Release( p_hvisor );
500+ p_hvcon->dw_status &= ~(HVISOR_STATUS_CONNECTING);
501+ p_hvisor->dw_status &= ~(HVISOR_STATUS_CONNECTING);
489502
490- }
503+ HVisor_Release( p_hvisor );
491504
492505 return i_err;
493506 }
--- a/src/sshcmd.c
+++ b/src/sshcmd.c
@@ -192,11 +192,12 @@ int
192192 /* ===========================================================================*/
193193 VMTUI_SSHCMD_EXTERN
194194 int
195- SSHCmd_Connect(
195+ SSHCmd_Connect_Phase1(
196196 HvConnect *p_hvcon,
197197 SSH_Info *pt_ssh )
198198 {
199199 int i_err;
200+ int i_value;
200201 struct hostent *pt_host;
201202
202203 p_hvcon->ssh.i_sock = socket(AF_INET, SOCK_STREAM, 0x00 );
@@ -204,17 +205,27 @@ int
204205 return -0x01;
205206 }
206207
208+ // Change Non-Blocking mode for connect(2) waiting ---
209+ i_value = 0x01;
210+ i_err = ioctl( p_hvcon->ssh.i_sock, FIONBIO, &i_value );
211+ if( 0 > i_err ) {
212+ close( p_hvcon->ssh.i_sock );
213+ p_hvcon->ssh.i_sock = -0x01;
214+ return -0x01;
215+ }
216+
207217 p_hvcon->ssh.t_sin.sin_family = AF_INET;
208218 p_hvcon->ssh.t_sin.sin_port = htons( pt_ssh->w_port );
209219 p_hvcon->ssh.t_sin.sin_addr.s_addr = inet_addr( pt_ssh->str_hostfqdn );
210220
221+ // Resolv IP addr from HostName ----
211222 if( 0xffffffff == p_hvcon->ssh.t_sin.sin_addr.s_addr ) {
212223 pt_host =gethostbyname( pt_ssh->str_hostfqdn );
213224 if( NULL == pt_host ) {
214225 ErrInfo_Warn( "Can't resolve SSH server hostname.",
215226 p_hvcon->i_id, GUEST_ID_NONE, REQUEST_ID_NONE,
216227 errno, 0x00, 0x00, pt_ssh->str_hostfqdn );
217- return -0x01;
228+ return -0x02;
218229 }
219230
220231 if( 4 == pt_host->h_length )
@@ -223,17 +234,76 @@ int
223234 ErrInfo_Warn( "Invalid IP addr. length",
224235 p_hvcon->i_id, GUEST_ID_NONE, REQUEST_ID_NONE,
225236 errno, (int)pt_host->h_length, 0x00, pt_ssh->str_hostfqdn );
226- return -0x02;
237+ return -0x03;
227238 }
228239 }
229240
230241 i_err = connect( p_hvcon->ssh.i_sock, (struct sockaddr *)&(p_hvcon->ssh.t_sin),
231242 sizeof( struct sockaddr_in));
232- if( 0x00 != i_err ) {
243+ if(( 0x00 != i_err ) && ( EINPROGRESS != errno )) {
233244 ErrInfo_Warn( "Failed connect() for SSH server",
234245 p_hvcon->i_id, GUEST_ID_NONE, REQUEST_ID_NONE,
235246 errno, i_err, 0x00, pt_ssh->str_hostfqdn );
236- return -0x03;
247+ return -0x04;
248+ }
249+
250+ return 0x00;
251+}
252+
253+/* ===========================================================================*/
254+VMTUI_SSHCMD_EXTERN
255+int
256+ SSHCmd_Connect_Phase2(
257+ HvConnect *p_hvcon,
258+ SSH_Info *pt_ssh )
259+{
260+ int i_err;
261+ int i_value;
262+ socklen_t t_len;
263+ int i_sockerr;
264+ fd_set t_rfd;
265+ fd_set t_wfd;
266+ fd_set t_efd;
267+ struct timeval t_tout;
268+ int i_sels;
269+
270+ // Check connect(2) status ---
271+ FD_ZERO( &t_rfd );
272+ FD_SET( p_hvcon->ssh.i_sock, &t_rfd );
273+ FD_ZERO( &t_wfd );
274+ FD_SET( p_hvcon->ssh.i_sock, &t_wfd );
275+ FD_ZERO( &t_efd );
276+ FD_SET( p_hvcon->ssh.i_sock, &t_efd );
277+ t_tout.tv_sec = 0;
278+ t_tout.tv_usec = 1;
279+ i_sels = select( p_hvcon->ssh.i_sock + 1, &t_rfd, &t_wfd, &t_efd, &t_tout );
280+ if( 0 == i_sels ) {
281+ // Not Error -- Continue connect(2) proc. ---
282+ return 0x01;
283+ }
284+ else if( 0 > i_sels ) {
285+ ErrInfo_Warn( "Failed check connecting status for HyperVisor (SSH) server.",
286+ p_hvcon->i_id, GUEST_ID_NONE, REQUEST_ID_NONE,
287+ errno, i_sels, 0, NULL);
288+ return -0x01;
289+ }
290+
291+ t_len = (socklen_t)sizeof( i_sockerr );
292+ i_err = getsockopt( p_hvcon->ssh.i_sock, SOL_SOCKET, SO_ERROR, &i_sockerr, &t_len);
293+ if( 0x00 < i_sockerr ) {
294+ ErrInfo_Warn( "Failed connect(2) for HyperVisor (SSH) server.",
295+ p_hvcon->i_id, GUEST_ID_NONE, REQUEST_ID_NONE,
296+ errno, i_sels, 0, NULL);
297+ return -0x02;
298+ }
299+
300+ // Change Blocking mode for connect(2) waiting ---
301+ i_value = 0x00;
302+ i_err = ioctl( p_hvcon->ssh.i_sock, FIONBIO, &i_value );
303+ if( 0 > i_err ) {
304+ close( p_hvcon->ssh.i_sock );
305+ p_hvcon->ssh.i_sock = -0x01;
306+ return -0x01;
237307 }
238308
239309 p_hvcon->ssh.pt_session = libssh2_session_init();
--- a/src/sshcmd.h
+++ b/src/sshcmd.h
@@ -37,7 +37,8 @@
3737 #endif
3838 VMTUI_SSHCMD_EXTERN int SSHCmd_ExecCmd( void *pv_hvcnt, char *pstr_cmdline );
3939 VMTUI_SSHCMD_EXTERN int SSHCmd_DisConnect( HvConnect *p_hvcon );
40-VMTUI_SSHCMD_EXTERN int SSHCmd_Connect( HvConnect *p_hvcon, SSH_Info *pt_ssh );
40+VMTUI_SSHCMD_EXTERN int SSHCmd_Connect_Phase1( HvConnect *p_hvcon, SSH_Info *pt_ssh );
41+VMTUI_SSHCMD_EXTERN int SSHCmd_Connect_Phase2( HvConnect *p_hvcon, SSH_Info *pt_ssh );
4142 VMTUI_SSHCMD_EXTERN int SSHCmd_Init( void );
4243 VMTUI_SSHCMD_EXTERN int SSHCmd_Term( void );
4344