Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d6306e93
authored
Nov 14, 2014
by
Marcus Winter
Committed by
unknown
Dec 11, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mtapi_network_c: added linux socket support
parent
54dfc55d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
mtapi_network_c/src/embb_mtapi_network.c
+8
-0
mtapi_network_c/src/embb_mtapi_network_socket.c
+28
-3
mtapi_network_c/src/embb_mtapi_network_socket.h
+4
-0
No files found.
mtapi_network_c/src/embb_mtapi_network.c
View file @
d6306e93
#include <embb_mtapi_network.h>
#ifdef _WIN32
#include <WinSock2.h>
#endif
int
embb_mtapi_network_initialize
()
{
#ifdef _WIN32
WORD
ver_request
;
WSADATA
wsa_data
;
int
err
;
...
...
@@ -15,8 +18,13 @@ int embb_mtapi_network_initialize() {
}
else
{
return
1
;
}
#else
return
1
;
#endif
}
void
embb_mtapi_network_finalize
()
{
#ifdef _WIN32
WSACleanup
();
#endif
}
mtapi_network_c/src/embb_mtapi_network_socket.c
View file @
d6306e93
...
...
@@ -2,7 +2,19 @@
#include <embb_mtapi_network_socket.h>
#include <string.h>
#ifdef _WIN32
#include <WinSock2.h>
#else
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#endif
int
embb_mtapi_network_socket_initialize
(
embb_mtapi_network_socket_t
*
that
)
{
...
...
@@ -17,7 +29,11 @@ int embb_mtapi_network_socket_initialize(
void
embb_mtapi_network_socket_finalize
(
embb_mtapi_network_socket_t
*
that
)
{
if
(
INVALID_SOCKET
!=
that
->
handle
)
{
#ifdef _WIN32
closesocket
(
that
->
handle
);
#else
close
(
that
->
handle
);
#endif
that
->
handle
=
INVALID_SOCKET
;
}
}
...
...
@@ -78,7 +94,11 @@ int embb_mtapi_network_socket_connect(
if
(
SOCKET_ERROR
==
connect
(
that
->
handle
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
)))
{
#ifdef _WIN32
if
(
WSAEWOULDBLOCK
!=
WSAGetLastError
())
#else
if
(
EAGAIN
!=
errno
)
#endif
return
0
;
}
...
...
@@ -101,9 +121,9 @@ int embb_mtapi_network_socket_select(
max_fd
=
that
->
handle
;
if
(
timeout
>=
0
)
{
err
=
select
(
max_fd
,
&
read_set
,
NULL
,
NULL
,
&
tv
);
err
=
select
(
max_fd
+
1
,
&
read_set
,
NULL
,
NULL
,
&
tv
);
}
else
{
err
=
select
(
max_fd
,
&
read_set
,
NULL
,
NULL
,
NULL
);
err
=
select
(
max_fd
+
1
,
&
read_set
,
NULL
,
NULL
,
NULL
);
}
if
(
0
==
err
)
{
// timeout
...
...
@@ -134,9 +154,14 @@ int embb_mtapi_network_socket_sendbuffer(
int
embb_mtapi_network_socket_recvbuffer
(
embb_mtapi_network_socket_t
*
that
,
embb_mtapi_network_buffer_t
*
buffer
)
{
u_long
bytes_available
=
0
;
int
err
;
#ifdef _WIN32
u_long
bytes_available
=
0
;
if
(
0
!=
ioctlsocket
(
that
->
handle
,
FIONREAD
,
&
bytes_available
))
#else
int
bytes_available
=
0
;
if
(
0
!=
ioctl
(
that
->
handle
,
FIONREAD
,
&
bytes_available
))
#endif
return
0
;
if
(
buffer
->
capacity
>
(
int
)
bytes_available
)
return
0
;
...
...
mtapi_network_c/src/embb_mtapi_network_socket.h
View file @
d6306e93
...
...
@@ -36,7 +36,11 @@ extern "C" {
struct
embb_mtapi_network_socket_struct
{
#ifdef _WIN32
unsigned
int
handle
;
#else
int
handle
;
#endif
};
typedef
struct
embb_mtapi_network_socket_struct
embb_mtapi_network_socket_t
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment