summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Knowles <alan_k@php.net>2002-08-15 09:23:41 +0000
committerAlan Knowles <alan_k@php.net>2002-08-15 09:23:41 +0000
commit0dc8cdd4c724f23fa1e8d8fb9c3fadd89a064735 (patch)
tree3c2590a588d1be78cc882967f76575591df6206b
parent6adcd3d353c3e0d2eface1537933dfe5e2367a9d (diff)
downloadphp-git-0dc8cdd4c724f23fa1e8d8fb9c3fadd89a064735.tar.gz
adding dio_tcsetattr and ASYNC support
-rw-r--r--ext/dio/dio.c182
-rw-r--r--ext/dio/php_dio.h1
2 files changed, 183 insertions, 0 deletions
diff --git a/ext/dio/dio.c b/ext/dio/dio.c
index efbced09eb..bf6acc4fcc 100644
--- a/ext/dio/dio.c
+++ b/ext/dio/dio.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
+#include <termios.h>
#define le_fd_name "Direct I/O File Descriptor"
static int le_fd;
@@ -42,6 +43,7 @@ function_entry dio_functions[] = {
PHP_FE(dio_read, NULL)
PHP_FE(dio_write, NULL)
PHP_FE(dio_close, NULL)
+ PHP_FE(dio_tcsetattr, NULL)
{NULL, NULL, NULL}
};
@@ -92,6 +94,7 @@ PHP_MINIT_FUNCTION(dio)
#ifdef O_SYNC
RDIOC(O_SYNC);
#endif
+ RDIOC(O_ASYNC);
RDIOC(O_NOCTTY);
RDIOC(S_IRWXU);
RDIOC(S_IRUSR);
@@ -408,6 +411,185 @@ PHP_FUNCTION(dio_fcntl)
}
/* }}} */
+
+/* {{{ proto mixed dio_tcsetattr(resource fd, array args )
+ Perform a c library tcsetattr on fd */
+PHP_FUNCTION(dio_tcsetattr)
+{
+ zval *r_fd;
+ zval *arg = NULL;
+ php_fd_t *f;
+ int cmd;
+ struct termios newtio;
+ int Baud_Rate, Data_Bits=8, Stop_Bits=0, Parity=1;
+ long BAUD,DATABITS,STOPBITS,PARITYON,PARITY;
+ HashTable *fh;
+ zval **element;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", &r_fd, &arg) == FAILURE) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(f, php_fd_t *, &r_fd, -1, le_fd_name, le_fd);
+
+
+ if (Z_TYPE_P(arg) != IS_ARRAY) {
+ zend_error(E_WARNING,"tcsetattr, third argument should be an associative array");
+ return;
+
+ }
+ fh = HASH_OF(arg);
+
+
+ if (zend_hash_find(fh, "baud", sizeof("baud"), (void **) &element) == FAILURE) {
+ Baud_Rate = 9600;
+ }
+ else {
+ Baud_Rate = Z_LVAL_PP(element);
+ }
+
+
+ if (zend_hash_find(fh, "bits", sizeof("bits"), (void **) &element) == FAILURE) {
+ Data_Bits = 8;
+ }
+ else {
+ Data_Bits = Z_LVAL_PP(element);
+ }
+
+ if (zend_hash_find(fh, "stop", sizeof("stop"), (void **) &element) == FAILURE) {
+ Stop_Bits = 8;
+ }
+ else {
+ Stop_Bits = Z_LVAL_PP(element);
+ }
+
+ if (zend_hash_find(fh, "parity", sizeof("parity"), (void **) &element) == FAILURE) {
+ Parity = 0;
+ }
+ else {
+ Parity = Z_LVAL_PP(element);
+ }
+
+ /* assign to correct values... */
+ switch (Baud_Rate) {
+ case 38400:
+
+ BAUD = B38400;
+ break;
+ case 19200:
+ BAUD = B19200;
+ break;
+ case 9600:
+ BAUD = B9600;
+ break;
+ case 4800:
+ BAUD = B4800;
+ break;
+ case 2400:
+ BAUD = B2400;
+ break;
+ case 1800:
+ BAUD = B1800;
+ break;
+ case 1200:
+ BAUD = B1200;
+ break;
+ case 600:
+ BAUD = B600;
+ break;
+ case 300:
+ BAUD = B300;
+ break;
+ case 200:
+ BAUD = B200;
+ break;
+ case 150:
+ BAUD = B150;
+ break;
+ case 134:
+ BAUD = B134;
+ break;
+ case 110:
+ BAUD = B110;
+ break;
+ case 75:
+ BAUD = B75;
+ break;
+ case 50:
+ BAUD = B50;
+ break;
+ default:
+ zend_error(E_WARNING, "invalid baud rate %d", Baud_Rate);
+ RETURN_FALSE;
+ }
+ switch (Data_Bits) {
+ case 8:
+ DATABITS = CS8;
+ break;
+ case 7:
+ DATABITS = CS7;
+ break;
+ case 6:
+ DATABITS = CS6;
+ break;
+ case 5:
+ DATABITS = CS5;
+ break;
+ default:
+ zend_error(E_WARNING, "invalid data bits %d", Data_Bits);
+ RETURN_FALSE;
+ }
+ switch (Stop_Bits) {
+ case 1:
+ STOPBITS = 0;
+ break;
+ case 2:
+ STOPBITS = CSTOPB;
+ break;
+ default:
+ zend_error(E_WARNING, "invalid stop bits %d", Stop_Bits);
+ RETURN_FALSE;
+ }
+ switch (Parity)
+ {
+ case 0:
+ PARITYON = 0;
+ PARITY = 0;
+ break;
+ case 1:
+ PARITYON = PARENB;
+ PARITY = PARODD;
+ break;
+ case 2:
+ PARITYON = PARENB;
+ PARITY = 0;
+ break;
+ default:
+ zend_error(E_WARNING, "invalid parity %d", Parity);
+ RETURN_FALSE;
+ }
+
+
+ newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
+ newtio.c_iflag = IGNPAR;
+ newtio.c_oflag = 0;
+ newtio.c_lflag = 0; /* ICANON; */
+ newtio.c_cc[VMIN]=1;
+ newtio.c_cc[VTIME]=0;
+ tcflush(f->fd, TCIFLUSH);
+ tcsetattr(f->fd,TCSANOW,&newtio);
+
+ RETURN_TRUE;
+
+
+
+
+
+
+}
+/* }}} */
+
+
+
/* {{{ proto void dio_close(resource fd)
Close the file descriptor given by fd */
PHP_FUNCTION(dio_close)
diff --git a/ext/dio/php_dio.h b/ext/dio/php_dio.h
index 39408c655c..41cbe01a10 100644
--- a/ext/dio/php_dio.h
+++ b/ext/dio/php_dio.h
@@ -44,6 +44,7 @@ PHP_FUNCTION(dio_read);
PHP_FUNCTION(dio_write);
PHP_FUNCTION(dio_fcntl);
PHP_FUNCTION(dio_close);
+PHP_FUNCTION(dio_tcsetattr);
typedef struct {
int fd;