summaryrefslogtreecommitdiff
path: root/pjlib/src/pj
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-01-20 21:03:36 +0000
committerBenny Prijono <bennylp@teluu.com>2006-01-20 21:03:36 +0000
commit7638eeee106fe58a1225f642e733629f29418818 (patch)
tree154947de290f76741923bbf8541dccd9c6386d93 /pjlib/src/pj
parent47e7de1c94be7f826080b3711451eafee894791f (diff)
Completed testing for WinCE port
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@126 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pj')
-rw-r--r--pjlib/src/pj/file_access_win32.c18
-rw-r--r--pjlib/src/pj/file_io_win32.c4
-rw-r--r--pjlib/src/pj/ioqueue_common_abs.c8
-rw-r--r--pjlib/src/pj/ioqueue_epoll.c4
-rw-r--r--pjlib/src/pj/ioqueue_select.c4
-rw-r--r--pjlib/src/pj/os_error_win32.c20
-rw-r--r--pjlib/src/pj/unicode_win32.c (renamed from pjlib/src/pj/compat/unicode_win32.c)26
7 files changed, 57 insertions, 27 deletions
diff --git a/pjlib/src/pj/file_access_win32.c b/pjlib/src/pj/file_access_win32.c
index 9c6d83c2..bec4904d 100644
--- a/pjlib/src/pj/file_access_win32.c
+++ b/pjlib/src/pj/file_access_win32.c
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <pj/file_access.h>
-#include <pj/compat/unicode.h>
+#include <pj/unicode.h>
#include <pj/assert.h>
#include <pj/errno.h>
#include <pj/string.h>
@@ -35,7 +35,7 @@ PJ_DEF(pj_bool_t) pj_file_exists(const char *filename)
PJ_ASSERT_RETURN(filename != NULL, 0);
- hFile = CreateFile(PJ_NATIVE_STRING(filename,wfilename), READ_CONTROL,
+ hFile = CreateFile(PJ_STRING_TO_NATIVE(filename,wfilename), READ_CONTROL,
FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
@@ -58,7 +58,7 @@ PJ_DEF(pj_off_t) pj_file_size(const char *filename)
PJ_ASSERT_RETURN(filename != NULL, -1);
- hFile = CreateFile(PJ_NATIVE_STRING(filename, wfilename), READ_CONTROL,
+ hFile = CreateFile(PJ_STRING_TO_NATIVE(filename, wfilename), READ_CONTROL,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
@@ -90,7 +90,7 @@ PJ_DEF(pj_status_t) pj_file_delete(const char *filename)
PJ_ASSERT_RETURN(filename != NULL, PJ_EINVAL);
- if (DeleteFile(PJ_NATIVE_STRING(filename,wfilename)) == FALSE)
+ if (DeleteFile(PJ_STRING_TO_NATIVE(filename,wfilename)) == FALSE)
return PJ_RETURN_OS_ERROR(GetLastError());
return PJ_SUCCESS;
@@ -109,12 +109,12 @@ PJ_DEF(pj_status_t) pj_file_move( const char *oldname, const char *newname)
PJ_ASSERT_RETURN(oldname!=NULL && newname!=NULL, PJ_EINVAL);
#if PJ_WIN32_WINNT >= 0x0400
- rc = MoveFileEx(PJ_NATIVE_STRING(oldname,woldname),
- PJ_NATIVE_STRING(newname,wnewname),
+ rc = MoveFileEx(PJ_STRING_TO_NATIVE(oldname,woldname),
+ PJ_STRING_TO_NATIVE(newname,wnewname),
MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING);
#else
- rc = MoveFile(PJ_NATIVE_STRING(oldname, woldname),
- PJ_NATIVE_STRING(newname, wnewname));
+ rc = MoveFile(PJ_STRING_TO_NATIVE(oldname, woldname),
+ PJ_STRING_TO_NATIVE(newname, wnewname));
#endif
if (!rc)
@@ -166,7 +166,7 @@ PJ_DEF(pj_status_t) pj_file_getstat(const char *filename, pj_file_stat *stat)
PJ_ASSERT_RETURN(filename!=NULL && stat!=NULL, PJ_EINVAL);
- hFile = CreateFile(PJ_NATIVE_STRING(filename,wfilename), READ_CONTROL,
+ hFile = CreateFile(PJ_STRING_TO_NATIVE(filename,wfilename), READ_CONTROL,
FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
diff --git a/pjlib/src/pj/file_io_win32.c b/pjlib/src/pj/file_io_win32.c
index bf8e11fa..e663e527 100644
--- a/pjlib/src/pj/file_io_win32.c
+++ b/pjlib/src/pj/file_io_win32.c
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <pj/file_io.h>
-#include <pj/compat/unicode.h>
+#include <pj/unicode.h>
#include <pj/errno.h>
#include <pj/assert.h>
@@ -78,7 +78,7 @@ PJ_DEF(pj_status_t) pj_file_open( pj_pool_t *pool,
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
- hFile = CreateFile(PJ_NATIVE_STRING(pathname,wpathname),
+ hFile = CreateFile(PJ_STRING_TO_NATIVE(pathname,wpathname),
dwDesiredAccess, dwShareMode, NULL,
dwCreationDisposition, dwFlagsAndAttributes, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
diff --git a/pjlib/src/pj/ioqueue_common_abs.c b/pjlib/src/pj/ioqueue_common_abs.c
index 9b59657e..168b4f1e 100644
--- a/pjlib/src/pj/ioqueue_common_abs.c
+++ b/pjlib/src/pj/ioqueue_common_abs.c
@@ -247,7 +247,6 @@ void ioqueue_dispatch_write_event(pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h)
*/
if (h->fd_type == PJ_SOCK_DGRAM) {
pj_list_erase(write_op);
- write_op->op = 0;
if (pj_list_empty(&h->write_list))
ioqueue_remove_from_set(ioqueue, h->fd, WRITEABLE_EVENT);
@@ -261,9 +260,11 @@ void ioqueue_dispatch_write_event(pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h)
*/
sent = write_op->size - write_op->written;
if (write_op->op == PJ_IOQUEUE_OP_SEND) {
+ write_op->op = 0;
send_rc = pj_sock_send(h->fd, write_op->buf+write_op->written,
&sent, write_op->flags);
} else if (write_op->op == PJ_IOQUEUE_OP_SEND_TO) {
+ write_op->op = 0;
send_rc = pj_sock_sendto(h->fd,
write_op->buf+write_op->written,
&sent, write_op->flags,
@@ -271,6 +272,7 @@ void ioqueue_dispatch_write_event(pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h)
write_op->rmt_addrlen);
} else {
pj_assert(!"Invalid operation type!");
+ write_op->op = 0;
send_rc = PJ_EBUG;
}
@@ -370,7 +372,6 @@ void ioqueue_dispatch_read_event( pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h )
/* Get one pending read operation from the list. */
read_op = h->read_list.next;
pj_list_erase(read_op);
- read_op->op = 0;
/* Clear fdset if there is no pending read. */
if (pj_list_empty(&h->read_list))
@@ -382,13 +383,16 @@ void ioqueue_dispatch_read_event( pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h )
bytes_read = read_op->size;
if ((read_op->op == PJ_IOQUEUE_OP_RECV_FROM)) {
+ read_op->op = 0;
rc = pj_sock_recvfrom(h->fd, read_op->buf, &bytes_read, 0,
read_op->rmt_addr,
read_op->rmt_addrlen);
} else if ((read_op->op == PJ_IOQUEUE_OP_RECV)) {
+ read_op->op = 0;
rc = pj_sock_recv(h->fd, read_op->buf, &bytes_read, 0);
} else {
pj_assert(read_op->op == PJ_IOQUEUE_OP_READ);
+ read_op->op = 0;
/*
* User has specified pj_ioqueue_read().
* On Win32, we should do ReadFile(). But because we got
diff --git a/pjlib/src/pj/ioqueue_epoll.c b/pjlib/src/pj/ioqueue_epoll.c
index 780ea37b..72e354d3 100644
--- a/pjlib/src/pj/ioqueue_epoll.c
+++ b/pjlib/src/pj/ioqueue_epoll.c
@@ -400,8 +400,10 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout)
msec = timeout ? PJ_TIME_VAL_MSEC(*timeout) : 9000;
count = os_epoll_wait( ioqueue->epfd, events, PJ_ARRAY_SIZE(events), msec);
- if (count <= 0)
+ if (count == 0)
return count;
+ else if (count < 0)
+ return -pj_get_netos_error();
/* Lock ioqueue. */
pj_lock_acquire(ioqueue->lock);
diff --git a/pjlib/src/pj/ioqueue_select.c b/pjlib/src/pj/ioqueue_select.c
index 1dfcb113..16a511a8 100644
--- a/pjlib/src/pj/ioqueue_select.c
+++ b/pjlib/src/pj/ioqueue_select.c
@@ -423,7 +423,7 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout)
enum ioqueue_event_type event_type;
} event[PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL];
- PJ_ASSERT_RETURN(ioqueue, PJ_EINVAL);
+ PJ_ASSERT_RETURN(ioqueue, -PJ_EINVAL);
/* Lock ioqueue before making fd_set copies */
pj_lock_acquire(ioqueue->lock);
@@ -460,7 +460,7 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout)
count = pj_sock_select(FD_SETSIZE, &rfdset, &wfdset, &xfdset, timeout);
if (count <= 0)
- return count;
+ return -pj_get_netos_error();
else if (count > PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL)
count = PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL;
diff --git a/pjlib/src/pj/os_error_win32.c b/pjlib/src/pj/os_error_win32.c
index 5001af4a..b8f0d039 100644
--- a/pjlib/src/pj/os_error_win32.c
+++ b/pjlib/src/pj/os_error_win32.c
@@ -21,6 +21,7 @@
#include <pj/compat/stdarg.h>
#include <pj/compat/sprintf.h>
#include <pj/compat/vsprintf.h>
+#include <pj/unicode.h>
#include <pj/string.h>
@@ -121,6 +122,7 @@ int platform_strerror( pj_os_err_type os_errcode,
char *buf, pj_size_t bufsize)
{
int len;
+ PJ_DECL_UNICODE_TEMP_BUF(wbuf,128);
pj_assert(buf != NULL);
pj_assert(bufsize >= 0);
@@ -131,14 +133,28 @@ int platform_strerror( pj_os_err_type os_errcode,
//PJ_CHECK_STACK();
*/
+#if PJ_NATIVE_STRING_IS_UNICODE
len = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
os_errcode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)buf,
- (DWORD)bufsize,
+ wbuf,
+ sizeof(wbuf),
NULL);
+ if (len) {
+ pj_unicode_to_ansi(wbuf, len, buf, bufsize);
+ }
+#else
+ len = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ os_errcode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ buf,
+ bufsize,
+ NULL);
+#endif
if (!len) {
int i;
diff --git a/pjlib/src/pj/compat/unicode_win32.c b/pjlib/src/pj/unicode_win32.c
index 4727210b..69b2b639 100644
--- a/pjlib/src/pj/compat/unicode_win32.c
+++ b/pjlib/src/pj/unicode_win32.c
@@ -16,23 +16,31 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <pj/compat/unicode.h>
+#include <pj/unicode.h>
#include <pj/assert.h>
#include <pj/string.h>
#include <windows.h>
-PJ_DEF(wchar_t*) pj_ansi_to_unicode(const char *s, wchar_t *buf,
- pj_size_t buf_count)
+PJ_DEF(wchar_t*) pj_ansi_to_unicode(const char *s, pj_size_t len,
+ wchar_t *buf, pj_size_t buf_count)
{
- int len;
+ PJ_ASSERT_RETURN(s && buf, NULL);
- PJ_ASSERT_RETURN(s, NULL);
-
- len = MultiByteToWideChar(CP_ACP, 0, s, strlen(s),
+ len = MultiByteToWideChar(CP_ACP, 0, s, len,
buf, buf_count);
- if (!len)
- return NULL;
+ buf[len] = 0;
+ return buf;
+}
+
+PJ_DEF(char*) pj_unicode_to_ansi( const wchar_t *wstr, pj_size_t len,
+ char *buf, pj_size_t buf_size)
+{
+ PJ_ASSERT_RETURN(wstr && buf, NULL);
+
+ len = WideCharToMultiByte(CP_ACP, 0, wstr, len, buf, buf_size, NULL, NULL);
+ buf[len] = '\0';
return buf;
}
+