- /* We can always do writes */
- printf("Begin doit main loop\n");
- /*
- * Link states: 0-idle, 1-read pending, 2-write pending, 3-closed.
- */
- for (link_state = 0; link_state < 3; ) {
- /*
- * Wait for remote end to request data action on A channel.
- */
- while ( link_state == 0 ) {
- status = get ( chan, (char *) &msg, sizeof(msg), &length );
- if ( (status&1) == 0 ) {
- printf("Error in main loop get: %d\n", status );
- link_state = 3;
- break;
- }
- if ( length < RPC_HDR_SIZE ) {
- printf("Error in main loop get size: %d\n", length );
- break;
- link_state = 3;
- }
- if ( msg.channel != 'A' ) {
- printf("Error in main loop, unexpected channel: %c\n",
- msg.channel );
- break;
- link_state = 3;
- }
- if ( msg.function == 'G' ) {
- link_state = 1;
- } else if ( msg.function == 'P' ) {
- link_state = 2; /* write pending */
- } else if ( msg.function == 'X' ) {
- link_state = 3;
- } else {
- link_state = 3;
- }
- }
- if ( link_state == 1 ) {
- i = BIO_read ( s_bio, msg.data, msg.length );
- if ( i < 0 ) link_state = 3;
- else {
- msg.channel = 'A';
- msg.function = 'C'; /* confirm */
- msg.length = i;
- status = put ( chan, (char *) &msg, i+RPC_HDR_SIZE );
- if ( (status&1) == 0 ) break;
- link_state = 0;
- }
- } else if ( link_state == 2 ) {
- i = BIO_write ( s_bio, msg.data, msg.length );
- if ( i < 0 ) link_state = 3;
- else {
- msg.channel = 'A';
- msg.function = 'C'; /* confirm */
- msg.length = 0;
- status = put ( chan, (char *) &msg, RPC_HDR_SIZE );
- if ( (status&1) == 0 ) break;
- link_state = 0;
- }
- }
- }
- fprintf(stdout,"DONE\n");
-err:
- /* We have to set the BIO's to NULL otherwise they will be
- * free()ed twice. Once when th s_ssl is SSL_free()ed and
- * again when c_ssl is SSL_free()ed.
- * This is a hack required because s_ssl and c_ssl are sharing the same
- * BIO structure and SSL_set_bio() and SSL_free() automatically
- * BIO_free non NULL entries.
- * You should not normally do this or be required to do this */
- s_ssl->rbio=NULL;
- s_ssl->wbio=NULL;
+ /* We can always do writes */
+ printf("Begin doit main loop\n");
+ /*
+ * Link states: 0-idle, 1-read pending, 2-write pending, 3-closed.
+ */
+ for (link_state = 0; link_state < 3;) {
+ /*
+ * Wait for remote end to request data action on A channel.
+ */
+ while (link_state == 0) {
+ status = get(chan, (char *)&msg, sizeof(msg), &length);
+ if ((status & 1) == 0) {
+ printf("Error in main loop get: %d\n", status);
+ link_state = 3;
+ break;
+ }
+ if (length < RPC_HDR_SIZE) {
+ printf("Error in main loop get size: %d\n", length);
+ break;
+ link_state = 3;
+ }
+ if (msg.channel != 'A') {
+ printf("Error in main loop, unexpected channel: %c\n",
+ msg.channel);
+ break;
+ link_state = 3;
+ }
+ if (msg.function == 'G') {
+ link_state = 1;
+ } else if (msg.function == 'P') {
+ link_state = 2; /* write pending */
+ } else if (msg.function == 'X') {
+ link_state = 3;
+ } else {
+ link_state = 3;
+ }
+ }
+ if (link_state == 1) {
+ i = BIO_read(s_bio, msg.data, msg.length);
+ if (i < 0)
+ link_state = 3;
+ else {
+ msg.channel = 'A';
+ msg.function = 'C'; /* confirm */
+ msg.length = i;
+ status = put(chan, (char *)&msg, i + RPC_HDR_SIZE);
+ if ((status & 1) == 0)
+ break;
+ link_state = 0;
+ }
+ } else if (link_state == 2) {
+ i = BIO_write(s_bio, msg.data, msg.length);
+ if (i < 0)
+ link_state = 3;
+ else {
+ msg.channel = 'A';
+ msg.function = 'C'; /* confirm */
+ msg.length = 0;
+ status = put(chan, (char *)&msg, RPC_HDR_SIZE);
+ if ((status & 1) == 0)
+ break;
+ link_state = 0;
+ }
+ }
+ }
+ fprintf(stdout, "DONE\n");
+ err:
+ /*
+ * We have to set the BIO's to NULL otherwise they will be free()ed
+ * twice. Once when th s_ssl is SSL_free()ed and again when c_ssl is
+ * SSL_free()ed. This is a hack required because s_ssl and c_ssl are
+ * sharing the same BIO structure and SSL_set_bio() and SSL_free()
+ * automatically BIO_free non NULL entries. You should not normally do
+ * this or be required to do this
+ */
+ s_ssl->rbio = NULL;
+ s_ssl->wbio = NULL;