[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[Vala] Socket bindings VAPI file
- From: Mikael Hermansson <mike tielie gmail com>
- To: Vala ML <vala-list gnome org>
- Subject: [Vala] Socket bindings VAPI file
- Date: Tue, 18 Mar 2008 23:46:18 +0100
Here is a small VAPI file that adds lowlevel socket API This is
Unix/Posix related API.
Right now I am using Posix as namespace.
Feel free to use/change or add to vala SVN.
Right now it has support for Posix socket API:
socket()
connect()
bind()
listen ()
accept()
getaddrinfo()
and its related structures.
Greets
Mikael Hermansson
/*
* File: posix.vapi - Bindings for posix socket API
*
* Copyright (C) 2008 - Mikael Hermansson
*
* This VAPI binding is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This VAPI binding 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace Posix {
[CCode (cname = "struct sockaddr", cheader_filename = "sys/types.h")]
public struct SockAddr {
public void* sa_family;
public uchar[] sa_data;
}
[CCode (cname = "struct addrinfo", cheader_filename = "sys/types.h", cheader_filename = "sys/socket.h")]
public struct AddrInfo
{
public int ai_flags;
public int ai_family;
public int ai_socktype;
public int ai_protocol;
public size_t ai_addrlen;
public SockAddr *ai_addr;
public string ai_canonname;
public AddrInfo *ai_next;
}
[CCode (cname="struct protoent", cheader_filename="netdb.h")]
struct protoent
{
string p_name; /* Official protocol name. */
string []p_aliases; /* Alias list. */
int p_proto; /* Protocol number. */
}
[CCode (cprefix = "O_", cheader_filename = "fcntl.h")]
public enum FcntlFlags{
NONBLOCK = 0x00004000,
APPEND = 0x00002000
}
[CCode (cprefix = "F_", cheader_filename = "fcntl.h")]
public enum FcntlCmd{
GETFL=1,
SETFL=2
}
[CCode (cprefix = "AF_", cheader_filename = "netdb.h")]
public enum Af{
UNSPEC = 0,
}
[CCode (cprefix = "AI_", cheader_filename = "netdb.h")]
public enum Ai{
PASSIVE = 0x0001,
CANONNAME = 0x0002,
NUMERICHOST = 0x0004,
V4MAPPED = 0x0008,
ALL = 0x0010,
ADDRCONFIG =0x0020,
IDN = 0x0040,
NUMERICSERV=0x0400
}
[CCode (cprefix = "SOCK_", cheader_filename = "netdb.h")]
public enum SockType{
STREAM = 1,
DATAGRAM = 2,
RAW = 3,
RDM = 4,
SEQPACKET = 5,
PACKET = 10
}
[CCode (cname="strerror", cheader_filename = "string.h")]
public static weak string strerror(int errno);
[CCode (cname="close", cheader_filename = "unistd.h")]
public static int close(int fd);
[CCode (cname="socket", cheader_filename = "sys/socket.h")]
public static int socket (int socket_family, int socket_type, int protocol);
[CCode (cname="bind", cheader_filename = "sys/socket.h")]
public static int bind (int sockfd, SockAddr adr, int socklenadr);
[CCode (cname="listen", cheader_filename = "sys/socket.h")]
public static int listen (int sockfd, int backlog);
[CCode (cname="accept", cheader_filename = "sys/socket.h")]
public static int accept (int sockfd, SockAddr adr, int socklenadr);
[CCode (cname="connect", cheader_filename = "sys/socket.h")]
public static int connect (int sockfd, SockAddr adr, size_t socklenadr);
[CCode (cname="fcntl", cheader_filename = "fcntl.h", cheader_filename = "unistd.h")]
public static int fcntl (int fd, FcntlCmd cmd, FcntlFlags flags=0);
[CCode (cname="getaddrinfo", cheader_filename = "sys/socket.h")]
public static int getaddrinfo (string hostname, string service_port, AddrInfo hint, AddrInfo *res);
[CCode (cname="freeaddrinfo", cheader_filename = "netdb.h", cheader_filename = "sys/types.h", cheader_filename = "sys/socket.h")]
public static int freeaddrinfo (AddrInfo *adr);
[CCode (cname="gai_strerror", cheader_filename = "netdb.h", cheader_filename = "sys/types.h", cheader_filename = "sys/socket.h")]
public static weak string! gai_strerror(int errno);
}
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]