Hi all,
The following program works only if compiled in the
POSIX shell *and* run from the shell. Annoyingly,
if compiled in POSIX, and run from CI, it fails
(select() times out).
If compiled from the CI, and run from CI or shell, it fails.
The definition of "fails" is: it hangs in select() until the
timeout expires. Note: select() calls HPSELECT, and we've used
Debug/iX to verify that correct-appearing parameters are passed
to HPSELECT for all four cases.
(Tested only on MPE/iX 5.5, PowerPatch 2)
Any help/explanations appreciated!
thanks,
SS
Source:
--------------------------------cut here-----------------------------------
/* sock.c 97/10/07 */
/* */
/* POSIX example: */
/* cc sock.c -o sock -lsocket */
/* ./sock */
/* socket() returned 11 */
/* connect() returned 0 */
/* calling select()... */
/* select() returned! */
/* Ok, got 3072 bytes. */
/* */
/* CI & POSIX example: */
/* RUN ./sock */
/* */
/* socket() returned 9 */
/* connect() returned 0 */
/* calling select()... */
/* FAILED, error 4. */
/* */
/* CI example: */
/* Note: library list from HP ESC note JA9210151100 */
/* :ccxl sock.c, $newpass, $null; info="-Aa" */
/* :link from=$oldpass, SOCKETRL.NET.SYS,LIBCINIT.LIB.SYS,& */
/* LIBCANSI.LIB.SYS,LIBMANSI.LIB.SYS,LIBCRAND.LIB.SYS;& */
/* to=sock.pub;cap=ia,ba,ph" */
/* :run sock.pub */
/* */
/* socket() returned 11 */
/* connect() returned 0 */
/* calling select()... */
/* FAILED, error 4. */
/* */
/* END OF PROGRAM */
/***************************************************************/
#define _SOCKET_SOURCE
#define _POSIX_SOURCE
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <signal.h>
#include <errno.h>
#define MAX_BYTES 8192
#define int32 int
/*********************************************************/
int32 get_msg (char *message, char *return_data, int32 *return_data_len)
{
int32
s = 0,
status = 0;
fd_set
fdset_in;
struct sockaddr_in
addr;
struct timeval
timeout;
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
(void) printf ("socket() returned %d\n", s);
if (s == -1)
return 1;
addr.sin_family = AF_INET;
addr.sin_port = htons (80); /* WWW port */
addr.sin_addr.s_addr = inet_addr ("198.102.6.12");
status = connect (s, (struct sockaddr *) &addr, sizeof (addr));
(void) printf ("connect() returned %d\n", status);
if (status == -1) {
close (s);
return 2;
}
if (!write (s, message, strlen (message))) {
close (s);
return 3;
}
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO (&fdset_in);
FD_SET (s, &fdset_in);
(void) printf ("calling select()...\n");
if (!select (s + 1, &fdset_in, NULL, NULL, &timeout)) {
close (s);
return 4;
}
(void) printf ("select() returned!\n");
*return_data_len = read (s, return_data, MAX_BYTES);
if (!*return_data_len) {
close (s);
return 5;
}
close (s);
return 0;
} /* get_msg proc */
/*********************************************************/
main ()
{
char
ret_msg [MAX_BYTES + 1];
int32
error = 0,
length = 0;
if ((error = get_msg ("GET /index.html\n", ret_msg, &length)))
printf ("FAILED, error %d.\n", error);
else
printf ("Ok, got %d bytes.\n", length);
} /* main proc */
/*********************************************************/
--------------------------------cut here-----------------------------------
--
Stan Sieler [log in to unmask]
http://www.allegro.com/sieler.html
|