Added file I/O and file access API
git-svn-id: https://svn.pjsip.org/repos/pjproject/main@18 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/ioqueue_winnt.c b/pjlib/src/pj/ioqueue_winnt.c
index afb75c5..32a7466 100644
--- a/pjlib/src/pj/ioqueue_winnt.c
+++ b/pjlib/src/pj/ioqueue_winnt.c
@@ -33,9 +33,9 @@
WSAOVERLAPPED overlapped;
pj_ioqueue_operation_e operation;
} generic_overlapped;
-
+
/*
- * OVERLAP structure for send and receive.
+ * OVERLAPPPED structure for send and receive.
*/
typedef struct ioqueue_overlapped
{
@@ -74,6 +74,14 @@
ioqueue_accept_rec accept;
#endif
};
+
+/* Type of handle in the key. */
+enum handle_type
+{
+ HND_IS_UNKNOWN,
+ HND_IS_FILE,
+ HND_IS_SOCKET,
+};
/*
* Structure for individual socket.
@@ -82,7 +90,8 @@
{
pj_ioqueue_t *ioqueue;
HANDLE hnd;
- void *user_data;
+ void *user_data;
+ enum handle_type hnd_type;
#if PJ_HAS_TCP
int connecting;
#endif
@@ -316,7 +325,8 @@
/* Build the key for this socket. */
rec = pj_pool_zalloc(pool, sizeof(pj_ioqueue_key_t));
rec->ioqueue = ioqueue;
- rec->hnd = (HANDLE)sock;
+ rec->hnd = (HANDLE)sock;
+ rec->hnd_type = HND_IS_SOCKET;
rec->user_data = user_data;
pj_memcpy(&rec->cb, cb, sizeof(pj_ioqueue_callback));
@@ -336,7 +346,7 @@
*key = rec;
return PJ_SUCCESS;
}
-
+
/*
* pj_ioqueue_unregister()
*/
@@ -362,7 +372,10 @@
key->connecting = 0;
pj_lock_release(ioqueue->lock);
}
-#endif
+#endif
+ if (key->hnd_type == HND_IS_FILE) {
+ CloseHandle(key->hnd);
+ }
return PJ_SUCCESS;
}
@@ -482,7 +495,7 @@
}
return -1;
}
-
+
/*
* pj_ioqueue_recv()
*
@@ -505,7 +518,7 @@
union operation_key *op_key_rec;
PJ_CHECK_STACK();
- PJ_ASSERT_RETURN(key && op_key && buffer, PJ_EINVAL);
+ PJ_ASSERT_RETURN(key && op_key && buffer && length, PJ_EINVAL);
op_key_rec = (union operation_key*)op_key->internal__;
op_key_rec->overlapped.wsabuf.buf = buffer;