From 7638eeee106fe58a1225f642e733629f29418818 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 20 Jan 2006 21:03:36 +0000 Subject: Completed testing for WinCE port git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@126 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/compat/unicode_win32.c | 38 ------------------------------ pjlib/src/pj/file_access_win32.c | 18 +++++++-------- pjlib/src/pj/file_io_win32.c | 4 ++-- pjlib/src/pj/ioqueue_common_abs.c | 8 +++++-- pjlib/src/pj/ioqueue_epoll.c | 4 +++- pjlib/src/pj/ioqueue_select.c | 4 ++-- pjlib/src/pj/os_error_win32.c | 20 ++++++++++++++-- pjlib/src/pj/unicode_win32.c | 46 +++++++++++++++++++++++++++++++++++++ 8 files changed, 86 insertions(+), 56 deletions(-) delete mode 100644 pjlib/src/pj/compat/unicode_win32.c create mode 100644 pjlib/src/pj/unicode_win32.c (limited to 'pjlib/src/pj') diff --git a/pjlib/src/pj/compat/unicode_win32.c b/pjlib/src/pj/compat/unicode_win32.c deleted file mode 100644 index 4727210b..00000000 --- a/pjlib/src/pj/compat/unicode_win32.c +++ /dev/null @@ -1,38 +0,0 @@ -/* $Id$ */ -/* - * Copyright (C)2003-2006 Benny Prijono - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include - - -PJ_DEF(wchar_t*) pj_ansi_to_unicode(const char *s, wchar_t *buf, - pj_size_t buf_count) -{ - int len; - - PJ_ASSERT_RETURN(s, NULL); - - len = MultiByteToWideChar(CP_ACP, 0, s, strlen(s), - buf, buf_count); - if (!len) - return NULL; - - return buf; -} 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 -#include +#include #include #include #include @@ -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 -#include +#include #include #include @@ -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 #include #include +#include #include @@ -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/unicode_win32.c b/pjlib/src/pj/unicode_win32.c new file mode 100644 index 00000000..69b2b639 --- /dev/null +++ b/pjlib/src/pj/unicode_win32.c @@ -0,0 +1,46 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include +#include + + +PJ_DEF(wchar_t*) pj_ansi_to_unicode(const char *s, pj_size_t len, + wchar_t *buf, pj_size_t buf_count) +{ + PJ_ASSERT_RETURN(s && buf, NULL); + + len = MultiByteToWideChar(CP_ACP, 0, s, len, + buf, buf_count); + 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; +} + -- cgit v1.2.3