+int anetUnixGenericConnect(char *err, char *path, int flags)
+{
+ int s;
+ struct sockaddr_un sa;
+
+ if ((s = anetCreateSocket(err,AF_LOCAL)) == ANET_ERR)
+ return ANET_ERR;
+
+ sa.sun_family = AF_LOCAL;
+ strncpy(sa.sun_path,path,sizeof(sa.sun_path)-1);
+ if (flags & ANET_CONNECT_NONBLOCK) {
+ if (anetNonBlock(err,s) != ANET_OK)
+ return ANET_ERR;
+ }
+ if (connect(s,(struct sockaddr*)&sa,sizeof(sa)) == -1) {
+ if (errno == EINPROGRESS &&
+ flags & ANET_CONNECT_NONBLOCK)
+ return s;
+
+ anetSetError(err, "connect: %s", strerror(errno));
+ close(s);
+ return ANET_ERR;
+ }
+ return s;
+}
+
+int anetUnixConnect(char *err, char *path)
+{
+ return anetUnixGenericConnect(err,path,ANET_CONNECT_NONE);
+}
+
+int anetUnixNonBlockConnect(char *err, char *path)
+{
+ return anetUnixGenericConnect(err,path,ANET_CONNECT_NONBLOCK);
+}
+