summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>1999-06-26 01:07:12 +0000
committerwtc%netscape.com <devnull@localhost>1999-06-26 01:07:12 +0000
commit09a282d9c2c6d114098e25e44213720ca7c3744d (patch)
tree939348f5dbd515c6384982cabad07bbfc4e4c596
parenta8ea8380e1afa1fe81c20db6024c61e49168076a (diff)
downloadnspr-hg-09a282d9c2c6d114098e25e44213720ca7c3744d.tar.gz
Checked in BeOS changes contributed by Duncan Wilcox (duncan@be.com).
Modified files: plevent.c, prstreams/Makefile, prlink.c, bfile.c, testfile.c, tmocon.c.
-rw-r--r--lib/ds/plevent.c35
-rw-r--r--lib/prstreams/Makefile7
-rw-r--r--pr/src/linking/prlink.c49
-rw-r--r--pr/src/md/beos/bfile.c380
-rw-r--r--pr/tests/testfile.c8
-rw-r--r--pr/tests/tmocon.c2
6 files changed, 242 insertions, 239 deletions
diff --git a/lib/ds/plevent.c b/lib/ds/plevent.c
index 9456d0ca..a939d9e3 100644
--- a/lib/ds/plevent.c
+++ b/lib/ds/plevent.c
@@ -97,6 +97,8 @@ struct PLEventQueue {
HWND eventReceiverWindow;
#elif defined(XP_OS2)
HWND eventReceiverWindow;
+#elif defined(XP_BEOS)
+ port_id eventport;
#endif
};
@@ -651,6 +653,28 @@ failed:
close(self->eventPipe[0]);
close(self->eventPipe[1]);
return PR_FAILURE;
+#elif defined(XP_BEOS)
+ /* hook up to the nsToolkit queue, however the appshell
+ * isn't necessairly started, so we might have to create
+ * the queue ourselves
+ */
+ char portname[64];
+ char semname[64];
+ sprintf(portname, "event%lx", self->handlerThread);
+ sprintf(semname, "sync%lx", self->handlerThread);
+
+ if((self->eventport = find_port(portname)) < 0)
+ {
+ /* create port
+ */
+ self->eventport = create_port(100, portname);
+
+ /* We don't use the sem, but it has to be there
+ */
+ create_sem(0, semname);
+ }
+
+ return PR_SUCCESS;
#else
return PR_SUCCESS;
#endif
@@ -725,9 +749,20 @@ _pl_NativeNotify(PLEventQueue* self)
#endif /* XP_UNIX */
#if defined(XP_BEOS)
+struct ThreadInterfaceData
+{
+ void *data;
+ int32 sync;
+};
+
static PRStatus
_pl_NativeNotify(PLEventQueue* self)
{
+ struct ThreadInterfaceData id;
+ id.data = self;
+ id.sync = false;
+ write_port(self->eventport, 'natv', &id, sizeof(id));
+
return PR_SUCCESS; /* Is this correct? */
}
#endif /* XP_BEOS */
diff --git a/lib/prstreams/Makefile b/lib/prstreams/Makefile
index 5467b99a..0fe73149 100644
--- a/lib/prstreams/Makefile
+++ b/lib/prstreams/Makefile
@@ -34,6 +34,10 @@ ifeq ($(OS_ARCH), IRIX)
endif
endif
+ifeq ($(OS_ARCH), BeOS)
+ CFLAGS += -frtti -fexceptions
+endif
+
INCLUDES = -I$(DIST)/include
HEADERS = *.h
@@ -98,6 +102,9 @@ endif
ifeq ($(OS_ARCH),SCOOS)
EXTRA_LIBS =
endif
+ifeq ($(OS_ARCH),BeOS)
+ EXTRA_LIBS = -lstdc++.r4 -L$(DIST)/lib -lnspr$(MOD_VERSION)
+endif
ifeq ($(OS_ARCH), UNIXWARE)
OS_LIBS += -lC
diff --git a/pr/src/linking/prlink.c b/pr/src/linking/prlink.c
index 78d84486..0592c05c 100644
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -638,25 +638,6 @@ PR_LoadLibrary(const char *name)
}
#endif
-#ifdef XP_BEOS
- {
- image_id h = load_add_on( name );
-
- if( h == B_ERROR || h <= 0 ) {
-
- h = 0;
- result = NULL;
- PR_DELETE( lm );
- lm = NULL;
- goto unlock;
- }
- lm->name = strdup(name);
- lm->dlh = (void*)h;
- lm->next = pr_loadmap;
- pr_loadmap = lm;
- }
-#endif
-
#ifdef XP_UNIX
#ifdef HAVE_DLL
{
@@ -687,6 +668,36 @@ PR_LoadLibrary(const char *name)
#endif /* XP_UNIX */
lm->refCount = 1;
+
+#ifdef XP_BEOS
+ {
+ image_info info;
+ int32 cookie = 0;
+ image_id h = B_ERROR;
+
+ while(get_next_image_info(0, &cookie, &info) == B_OK)
+ if(strcmp(name, info.name + strlen(info.name) - strlen(name)) == 0) {
+ h = info.id;
+ lm->refCount++; /* it has been already loaded implcitly, so pretend it already had a control structure and ref */
+ }
+
+ if(h == B_ERROR)
+ h = load_add_on( name );
+
+ if( h == B_ERROR || h <= 0 ) {
+ h = 0;
+ result = NULL;
+ PR_DELETE( lm );
+ lm = NULL;
+ goto unlock;
+ }
+ lm->name = strdup(name);
+ lm->dlh = (void*)h;
+ lm->next = pr_loadmap;
+ pr_loadmap = lm;
+ }
+#endif
+
result = lm; /* success */
PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (load lib)", lm->name));
diff --git a/pr/src/md/beos/bfile.c b/pr/src/md/beos/bfile.c
index ad32c60c..321c9274 100644
--- a/pr/src/md/beos/bfile.c
+++ b/pr/src/md/beos/bfile.c
@@ -491,232 +491,182 @@ int rv, err;
PRInt32
_MD_pr_poll (PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
{
- PRPollDesc *pd, *epd;
- PRInt32 n, err, pdcnt;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- fd_set rd, wt, ex;
+ PRInt32 rc = 0;
+ fd_set rd, wr;
struct timeval tv, *tvp = NULL;
- int maxfd = -1;
- int rv;
-
- ConnectListNode currentConnectList[64];
- int currentConnectListCount = 0;
- int i,j;
- int connectResult = 0;
- int connectError = 0;
-
- /*
- * For restarting _MD_SELECT() if it is interrupted by a signal.
- * We use these variables to figure out how much time has elapsed
- * and how much of the timeout still remains.
- */
- PRIntervalTime start, elapsed, remaining;
+ PRPollDesc *pd, *epd;
+ int i = 0, j = 0;
+ int maxfd = -1;
+ PRInt32 osfd;
+ PRInt16 in_flags;
+ PRFileDesc *bottom;
+
+ /*printf("POLL: entering _MD_pr_poll\n");*/
+
+ /*
+ * Is it an empty set? If so, just sleep for the timeout and return
+ */
+ if (npds < 1)
+ {
+ /*printf("POLL: empty set. exiting _MD_pr_poll\n");*/
+ PR_Sleep(timeout);
+ return rc;
+ }
FD_ZERO(&rd);
- FD_ZERO(&wt);
- FD_ZERO(&ex);
+ FD_ZERO(&wr);
- for (pd = pds, epd = pd + npds; pd < epd; pd++) {
- PRInt32 osfd;
- PRInt16 in_flags = pd->in_flags;
- PRFileDesc *bottom = pd->fd;
-
- if ((NULL == bottom) || (in_flags == 0)) {
- continue;
- }
- while (bottom->lower != NULL) {
- bottom = bottom->lower;
- }
- osfd = bottom->secret->md.osfd;
-
- if( (in_flags & PR_POLL_WRITE) || (in_flags & PR_POLL_EXCEPT) ) {
-
- PR_Lock( _connectLock );
-
- for( i = 0; i < connectCount; i++ ) {
-
- if( connectList[i].osfd == osfd ) {
-
- memcpy( &currentConnectList[currentConnectListCount], &connectList[i], sizeof( connectList[i] ) );
- currentConnectListCount++;
- break;
- }
- }
-
- PR_Unlock( _connectLock );
- }
-
- if (in_flags & PR_POLL_READ) {
- FD_SET(osfd, &rd);
- if( osfd > maxfd ) maxfd = osfd;
- }
- }
- if (timeout != PR_INTERVAL_NO_TIMEOUT) {
- tv.tv_sec = PR_IntervalToSeconds(timeout);
- tv.tv_usec = PR_IntervalToMicroseconds(timeout) % PR_USEC_PER_SEC;
- tvp = &tv;
- start = PR_IntervalNow();
- }
-
- if( currentConnectListCount > 0 ) {
-
- tv.tv_sec = 0;
- tv.tv_usec = 100000L;
- tvp = &tv;
- start = PR_IntervalNow();
- }
-
-retry:
- if( currentConnectListCount > 0 ) {
-
- for( i = 0; i < currentConnectListCount; i++ ) {
-
- connectResult = connect( currentConnectList[i].osfd,
- &currentConnectList[i].addr,
- &currentConnectList[i].addrlen );
- connectError = _MD_ERRNO();
-
- if( ( connectResult < 0 ) &&
- ( connectError == EINTR ||
- connectError == EWOULDBLOCK ||
- connectError == EINPROGRESS ||
- connectError == EALREADY ) ) {
-
- continue;
+ /*
+ * first, sort out the new connects, the reads, and the writes
+ */
+ epd = pds + npds;
+ for(pd = pds; pd < epd; pd++)
+ {
+ in_flags = pd->in_flags;
+ bottom = pd->fd;
+
+ if(bottom != 0 && in_flags != 0)
+ {
+ while(bottom->lower != 0)
+ {
+ bottom = bottom->lower;
+ }
+ osfd = bottom->secret->md.osfd;
+
+ if(in_flags & PR_POLL_WRITE || in_flags & PR_POLL_EXCEPT)
+ {
+ /*printf("POLL: adding to write\n");*/
+ FD_SET(osfd, &wr);
+ if( osfd > maxfd ) maxfd = osfd;
+ }
+ if(in_flags & PR_POLL_READ || in_flags & PR_POLL_EXCEPT)
+ {
+ /*printf("POLL: adding to read\n");*/
+ FD_SET(osfd, &rd);
+ if( osfd > maxfd ) maxfd = osfd;
+ }
}
+
+
+ }
- PR_Lock( _connectLock );
-
- for( j = 0; j < connectCount; j++ ) {
-
- if( connectList[j].osfd == currentConnectList[i].osfd ) {
-
- if( j == ( connectCount - 1 ) ) {
-
- connectList[j].osfd = -1;
-
- } else {
+ if(maxfd >= 0)
+ {
+ PRInt32 n;
+ do {
+ PRIntervalTime start = PR_IntervalNow();
+ if (timeout != PR_INTERVAL_NO_TIMEOUT)
+ {
+ /*printf("POLL: timeout = %ld\n", (long) PR_IntervalToMicroseconds(timeout));*/
+ tv.tv_sec = PR_IntervalToSeconds(timeout);
+ tv.tv_usec = PR_IntervalToMicroseconds(timeout) % PR_USEC_PER_SEC;
+ tvp = &tv;
+ }
- for( ; j < connectCount; j++ )
- memcpy( &connectList[j], &connectList[j+1], sizeof( connectList[j] ) );
+
+ n = select(maxfd + 1, &rd, &wr, 0, tvp);
+ /*printf("POLL: maxfd = %d, select returns %d\n", maxfd, n);*/
+ if ((n <= 0) && (timeout != PR_INTERVAL_NO_TIMEOUT))
+ {
+ timeout -= PR_IntervalNow() - start;
+ if(timeout <= 0)
+ {
+ /* timed out */
+ n = 0;
+ }
+ }
+
+ } while(n < 0 && errno == EINTR);
+
+ if(n > 0)
+ {
+ epd = pds + npds;
+ for(pd = pds; pd < epd; pd++)
+ {
+ int selected;
+ in_flags = pd->in_flags;
+ bottom = pd->fd;
+ selected = 0;
+
+ if(bottom != 0 && in_flags != 0)
+ {
+ while(bottom->lower != 0)
+ {
+ bottom = bottom->lower;
+ }
+ osfd = bottom->secret->md.osfd;
+ if (FD_ISSET(osfd, &rd))
+ {
+ pd->out_flags |= PR_POLL_READ;
+ selected++;
+ }
+ if (FD_ISSET(osfd, &wr))
+ {
+ pd->out_flags |= PR_POLL_WRITE;
+ selected++;
+ }
+
+ if(selected > 0)
+ {
+ rc++;
+ /*
+ * check if it is a pending connect
+ */
+ PR_Lock( _connectLock );
+ for( i = 0; i < connectCount; i++ )
+ {
+ if(connectList[i].osfd == osfd)
+ {
+ int connectError;
+ int connectResult;
+
+ connectResult = connect(connectList[i].osfd,
+ &connectList[i].addr,
+ connectList[i].addrlen);
+ connectError = errno;
+
+ if(connectResult < 0 )
+ {
+ if(connectError == EINTR || connectError == EWOULDBLOCK
+ || connectError == EINPROGRESS || connectError == EALREADY)
+ {
+ break;
+ }
+ }
+
+ if(i == (connectCount - 1))
+ {
+ connectList[i].osfd = -1;
+ } else {
+ for(j = i; j < connectCount; j++ )
+ {
+ memcpy( &connectList[j], &connectList[j+1],
+ sizeof(connectList[j]));
+ }
+ }
+ connectCount--;
+
+ bottom->secret->md.connectReturnValue = connectResult;
+ bottom->secret->md.connectReturnError = connectError;
+ bottom->secret->md.connectValueValid = PR_TRUE;
+ break;
+ }
+ }
+
+
+ PR_Unlock( _connectLock );
+ }
+ } else {
+ pd->out_flags = 0;
+ continue;
+ }
+
}
- connectCount--;
- break;
- }
}
-
- PR_Unlock( _connectLock );
-
- FD_ZERO( &rd );
- FD_SET( currentConnectList[i].osfd, &wt );
- FD_SET( currentConnectList[i].osfd, &ex );
- n = 1;
- goto afterselect;
}
- }
-
- if( maxfd == -1 ) {
- snooze( 100000L );
- goto retry;
- }
- n = select(maxfd + 1, &rd, NULL, NULL, tvp);
-afterselect:
- if ( (n == -1 && errno == EINTR) || (n == 0 && currentConnectListCount > 0 ) ) {
- if (timeout == PR_INTERVAL_NO_TIMEOUT) {
- goto retry;
- } else {
- elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
- if (elapsed > timeout) {
- n = 0; /* timed out */
- } else {
- remaining = timeout - elapsed;
- tv.tv_sec = PR_IntervalToSeconds(remaining);
- tv.tv_usec = PR_IntervalToMicroseconds(
- remaining - PR_SecondsToInterval(tv.tv_sec));
- goto retry;
- }
- }
- }
-
- if (n > 0) {
- n = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++) {
- PRInt32 osfd;
- PRInt16 in_flags = pd->in_flags;
- PRInt16 out_flags = 0;
- PRFileDesc *bottom = pd->fd;
-
- if ((NULL == bottom) || (in_flags == 0)) {
- pd->out_flags = 0;
- continue;
- }
- while (bottom->lower != NULL) {
- bottom = bottom->lower;
- }
- osfd = bottom->secret->md.osfd;
-
- if ((in_flags & PR_POLL_READ) && FD_ISSET(osfd, &rd)) {
- out_flags |= PR_POLL_READ;
- }
- if ((in_flags & PR_POLL_WRITE) && FD_ISSET(osfd, &wt)) {
- out_flags |= PR_POLL_WRITE;
- }
- if ((in_flags & PR_POLL_EXCEPT) && FD_ISSET(osfd, &ex)) {
- out_flags |= PR_POLL_EXCEPT;
- }
- if ( FD_ISSET(osfd, &wt) && FD_ISSET(osfd, &ex ) ) {
-
- bottom->secret->md.connectReturnValue = connectResult;
- bottom->secret->md.connectReturnError = connectError;
- bottom->secret->md.connectValueValid = PR_TRUE;
- }
-
- pd->out_flags = out_flags;
- if (out_flags) {
- n++;
- }
- }
- PR_ASSERT(n > 0);
- } else if (n < 0) {
- err = _MD_ERRNO();
- if (err == EBADF) {
- /* Find the bad fds */
- n = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++) {
- int optval;
- int optlen = sizeof(optval);
- PRFileDesc *bottom = pd->fd;
-
- pd->out_flags = 0;
- if ((NULL == bottom) || (pd->in_flags == 0)) {
- continue;
- }
- while (bottom->lower != NULL) {
- bottom = bottom->lower;
- }
-#if 0
-/*
- * BeOS doesn't have this feature of getsockopt.
-*/
- if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET,
- SO_TYPE, (char *) &optval, &optlen) == -1) {
- PR_ASSERT(_MD_ERRNO() == ENOTSOCK);
- if (_MD_ERRNO() == ENOTSOCK) {
- pd->out_flags = PR_POLL_NVAL;
- n++;
- }
- }
-#endif
- }
- PR_ASSERT(n > 0);
- } else {
- PR_ASSERT(err != EINTR); /* should have been handled above */
- _PR_MD_MAP_SELECT_ERROR(err);
- }
- }
- return n;
+ /*printf("POLL: exiting _MD_pr_poll\n");*/
+ return rc;
}
/*
diff --git a/pr/tests/testfile.c b/pr/tests/testfile.c
index 05849d4f..ffc9798a 100644
--- a/pr/tests/testfile.c
+++ b/pr/tests/testfile.c
@@ -642,14 +642,14 @@ HANDLE hfile;
}
PR_Close(fd_file);
}
-#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2)
+#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2) || defined(XP_BEOS)
/*
* Create a hidden file - a platform-dependent operation
*/
strcpy(pathname, TEST_DIR);
strcat(pathname, "/");
strcat(pathname, HIDDEN_FILE_NAME);
-#if defined(XP_UNIX) || defined(XP_MAC)
+#if defined(XP_UNIX) || defined(XP_MAC) || defined(XP_BEOS)
DPRINTF(("Creating hidden test file %s\n",pathname));
fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
@@ -759,7 +759,7 @@ HANDLE hfile;
* List all files, including hidden files
*/
DPRINTF(("Listing all files in directory %s\n",TEST_DIR));
-#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2)
+#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2) || defined(XP_BEOS)
num_files = FILES_IN_DIR + 1;
#else
num_files = FILES_IN_DIR;
@@ -795,7 +795,7 @@ HANDLE hfile;
PR_CloseDir(fd_dir);
-#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2)
+#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2) || defined(XP_BEOS)
/*
* List all files, except hidden files
diff --git a/pr/tests/tmocon.c b/pr/tests/tmocon.c
index f941a4ee..ecf5e52a 100644
--- a/pr/tests/tmocon.c
+++ b/pr/tests/tmocon.c
@@ -47,7 +47,7 @@
#include <string.h>
/* for getcwd */
-#if defined(XP_UNIX) || defined (XP_OS2_EMX)
+#if defined(XP_UNIX) || defined (XP_OS2_EMX) || defined(XP_BEOS)
#include <unistd.h>
#elif defined(XP_PC)
#include <direct.h>